text value within a datastream always comes as nil

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:



datastream.StreamToServer("CallIn", {["text"] = "availmaps"})


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:



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)..".
")
	end
end
datastream.Hook("CallIn", answerCall)


For whatever reason, the text if coming back as nil, causing to fall back on the else statement, and giving me this error:



Received incorrect encoded.text in function answerCall. The sender was: Player [1][[FH]TGP1994], and encoded.text was: nil.


If anyone could help, that would be great.

if encoded.text == “availmaps” then

Will want to use decoded instead of encoded.

Why did you copy what I had?

@DaveParker: 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:)



includes/modules/datastream.lua:406: attempt to call field 'func' (a nil value)


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 :smiley:
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)…”.
")
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.

WOW. It was to call attention to the fact that you were using encoded instead of decoded. Massive fail.

You should have told him what he was doing wrong.

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.

I thought it would be obvious, because I was calling attention to the word encoded.

Well, you have to remember, this is in the section Nembie Questions :wink: 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.