• Usermessage giving the wrong value.
    7 replies, posted
Serverside I have something such as : [lua]function meta:UpdateMoney(amount) self.Money = amount SendUserMessage("ClientMoneyUpdate", self, amount) -- Notify the client their money has changed. print("Sent : "..amount) end[/lua] Clientside I have this : [lua]local function ClientMoneyUpdate( um ) LocalPlayer().Money = um:ReadShort() print("Got: "..LocalPlayer().Money) end usermessage.Hook("ClientMoneyUpdate", ClientMoneyUpdate)[/lua] The problem only occurs the first time the usermessage is sent, which is in PlayerInitialSpawn. In this case it just so happens to send the value 1337:ninja: serverside and retrieves the value 26210 clientside. What gives?
-snip-
[QUOTE=Dlaor;17973688]That's because on the client you are using the total money amount, not the amount of money received.[/QUOTE] How comes? I am using the data sent by the server. There is no other number around at this time. Also any subsequent usermessage behaves properly and receives the value sent by the server.
[QUOTE=Dlaor;17973688]That's because on the client you are using the total money amount, not the amount of money received.[/QUOTE] What. [QUOTE=Crazy Quebec;17970501]What gives?[/QUOTE] That's probably stupid, but what happens if you send the value as Int instead of Short? Also, try storing um:ReadShort() into a local variable, and then print that variable. LocalPlayer() has a kinda weird behaviour sometimes, at least for me.
SendUserMessage() sends Longs not Shorts.
[QUOTE=Lexic;17973822]SendUserMessage() sends Longs not Shorts.[/QUOTE] Oh, true that, I didn't even notice he used SendUserMessage. :v: Yeah, avoid using that function whenever you need to send values and stuff like that.
[QUOTE=iRzilla;17973987]SendUsermessage() is a default function?[/QUOTE] But it's also a convenience function that doesn't know how big the numbers you use are, so it sends the biggest type possible. (I think) I'll try sending a regular usermessage asap. [editline]01:45PM[/editline] Well sending the value as a Short fixed the issue, but gave me a new and unrelated(?) one. [lua]print(um:ReadShort()) LocalPlayer().Money = um:ReadShort() print(LocalPlayer().Money)[/lua] It prints : 1337 0 [editline]02:00PM[/editline] Nevermind that was a silly error. Removing the print obviously fixed it.:3:
Sorry, you need to Log In to post a reply to this thread.