• text value within a datastream always comes as nil
    8 replies, posted
Hi everyone. As some of you know, I'm making my own map system for the public (2.01) Zombie Survival. This is kind of working as my learning of lua, too. So anyways, I have a datastream initiating from a client script to ask the server for a list of maps. That part of the client script looks like this: [code] datastream.StreamToServer("CallIn", {["text"] = "availmaps"}) [/code] Then the server's lua file receives it, and is supposed to look at the text variable and decide what to do from there. Here's that: [code] function GM:AcceptStream(pl,handler,id) return true end function answerCall(player, handle, id, encoded, decoded) --Multi purpouse answering machine :D if encoded.text == "availmaps" then datastream.StreamToClients(player, "ReplyWithMaps", {["table"] = availmaps}) else ErrorNoHalt("Received incorrect encoded.text in function answerCall. The sender was: "..tostring(player)..", and encoded.text was: "..tostring(encoded.text)..".\n") end end datastream.Hook("CallIn", answerCall) [/code] For whatever reason, the text if coming back as nil, causing to fall back on the else statement, and giving me this error: [code] Received incorrect encoded.text in function answerCall. The sender was: Player [1][[FH]TGP1994], and encoded.text was: nil. [/code] If anyone could help, that would be great.
if [b]encoded[/b].text == "availmaps" then
[QUOTE=yakahughes;20472719]if [b]encoded[/b].text == "availmaps" then[/QUOTE] Why did you copy what I had? [b]@DaveParker:[/b] For some reason the tutorial in the wiki always uses encoded, but I will give decoded a try. [editline]10:51AM[/editline] And this time, datastream the module gets an error: (when I use decoded:) [code] includes/modules/datastream.lua:406: attempt to call field 'func' (a nil value) [/code] And the updated server script looks like this now: [lua] function GM:AcceptStream(pl,handler,id) return true end function answerCall(player, handle, id, encoded, decoded) --Multi purpouse answering machine :D if decoded.text == "availmaps" then datastream.StreamToClients(player, "ReplyWithMaps", {["table"] = availmaps}) else ErrorNoHalt("Received incorrect decoded.text in function answerCall. The sender was: "..tostring(player)..", and encoded.text was: "..tostring(decoded.text)..".\n") end end datastream.Hook("CallIn", answerCall) [/lua] [editline]11:31AM[/editline] Can anyone help? [editline]12:29PM[/editline] Well, I think I can call this a closed case. I was doing something wrong here, but I'm re-engineering the communication system so it's more efficient.
[QUOTE=tgp1994;20472924]Why did you copy what I had? [/QUOTE] WOW. It was to call attention to the fact that you were using encoded instead of decoded. Massive fail.
[QUOTE=yakahughes;20493014]WOW. It was to call attention to the fact that you were using encoded instead of decoded. Massive fail.[/QUOTE] You should have told him what he was doing wrong.
[quote=yakahughes]WOW. It was to call attention to the fact that you were using encoded instead of decoded. Massive fail. [/quote] [quote=MakeR]You should have told him what he was doing wrong.[/quote] Actually sir, the fail is on your part. I agree with MakeR; you weren't helping in the least by bolding something I had typed.
[QUOTE=tgp1994;20497353]Actually sir, the fail is on your part. I agree with MakeR; you weren't helping in the least by bolding something I had typed.[/QUOTE] I thought it would be obvious, because I was calling attention to the word encoded.
[QUOTE=yakahughes;20503717]I thought it would be obvious, because I was calling attention to the word encoded.[/QUOTE] Well, you have to remember, this is in the section Nembie Questions ;) Most newbies like me don't know how the heck datastream works, and in fact, the tutorial wiki article was wrong, before I learned here what the difference was and fixed it back at the wiki.
Sorry, you need to Log In to post a reply to this thread.