Jump to content

Display Food Values [Server and Client]


Recommended Posts

edit: Now Working - Here is the steam workshop link - http://steamcommunity.com/sharedfiles/filedetails/?id=458940297

 

So, the mod is pretty close to being finished but I have a funny bug that I can't seem to fix.

 

Everything works, both on client and on the server, but the values are always for the previous item looked at. I am not sure if there is a way to make sure that it runs sequentially to make sure that it updates the values before it returns the string but it seems there would be someway to force an update before it continues. I did try use player:DoTaskInTime but then it wouldn't update at all. This has been quite the project for me figuring this out and I would love it get it completed. Any help would be great.

 

The relevant files are attached.

FoodValues.lua

modmain.lua

Edited by gregdwilson
Link to comment
Share on other sites

?

AddClassPostConstruct("widgets/itemtile", function(self)	local player = GLOBAL.ThePlayer	function self:UpdateTooltip()		local str = self:GetDescriptionString()		player:ListenForEvent("foodstring_changed", function()			self:SetTooltip(str)			if self.item:GetIsWet() then				self:SetTooltipColour(unpack(WET_TEXT_COLOUR))			else				self:SetTooltipColour(unpack(NORMAL_TEXT_COLOUR))			end				end)	endend)
Link to comment
Share on other sites

That seems to halt the code before it even starts. I think its because that only runs once, when you mouse over the item, and it doesn't wait for the ListenForEvent to occur, it just instead passes over the code. I've also found that if you leave the mouse over the inventory item (with the original code) and then press the keyboard button to move then it updates the tooltip.  It may be that there just needs to be a break for the data to be sent to the server,  for the server to process it and then send it back. Is there code that pauses until something changes or even could just pause the code for a given amount of time? The time thing worries me though because then it could mess up if you had any lag.

Link to comment
Share on other sites

local function UpdateAfterRPC(self)	local str = self:GetDescriptionString()	self:SetTooltip(str)	if self.item:GetIsWet() then		self:SetTooltipColour(GLOBAL.unpack(GLOBAL.WET_TEXT_COLOUR))	else		self:SetTooltipColour(GLOBAL.unpack(GLOBAL.NORMAL_TEXT_COLOUR))	end endAddClassPostConstruct("widgets/itemtile", function(self)    local player = GLOBAL.ThePlayer    function self:UpdateTooltip()		SendModRPCToServer(MOD_RPC["Food Item"]["FIU"], self.item)        player:ListenForEvent("healthvalue_changed_dirty", function() UpdateAfterRPC(self) end)		player:ListenForEvent("hungervalue_changed_dirty", function() UpdateAfterRPC(self) end)		player:ListenForEvent("sanityvalue_changed_dirty", function() UpdateAfterRPC(self) end)    endend)

And remove/comment out the

SendModRPCToServer(MOD_RPC["Food Item"]["FIU"], self.item)

inside your GetDescriptionString() in modmain.

Link to comment
Share on other sites

Thank you. I actually just got it working right before you posted that. It is essentially the same solution but I added a single net variable to push an event after everything is updated. I then put a listener in the OnGainFocus() function (Putting in in the UpdateTooltip function made it so that the client was still one item behind for some reason, beats me) and called the UpdateTooltip function in the listener. Thank you for your help and setting me in the right direction. This should be up on steam after a little testing.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...