Why the hell does this error? i have no idea why this is happening.
[lua]function Sun_ReceiveShipData(handler,id,encoded,decoded)
DebugPrint(decoded.Entity,decoded.Name,decoded.Value)
decoded.Entity.NWData = decoded.Entity.NWData or {}
decoded.Entity.NWData[decoded.Name] = decoded.Value
end
datastream.Hook("Sun_SetShipData",Sun_ReceiveShipData)[/lua]
[editline]12:54PM[/editline]
Sorry if this is "The wrong section" like last time, i have no idea when to place it into "Newbie questions"
That's what i thought, try replacing encoded with decoded.
[editline]12:13PM[/editline]
[QUOTE=kevkev;16998672]Sorry if this is "The wrong section" like last time, i have no idea when to place it into "Newbie questions" [/QUOTE]
If it is any sort of question to do with Lua, i would put it in newbie questions to be safe.
[QUOTE=Dave_Parker;16998807]I thought encoded was the glon string. Could be wrong though.[/QUOTE]
Even if so, it would not give me this error.
[editline]02:46PM[/editline]
[QUOTE=Dave_Parker;16998858]But ehh, you're sending ship data client -> server? Exploitable.[/QUOTE]
No, this is from server to client.
[QUOTE=kevkev;16999617]Even if so, it would not give me this error.
[editline]02:46PM[/editline]
No, this is from server to client.[/QUOTE]
It would, since you're trying to index Entity from a string (which ends up being nil, since there's no string.Entity table).
Try it with decoded.
[QUOTE=MakeR;16998818]That's what i thought, try replacing encoded with decoded.
[editline]12:13PM[/editline]
If it is any sort of question to do with Lua, i would put it in newbie questions to be safe.[/QUOTE]
Decoded is nil somehow.
[editline]05:44PM[/editline]
I noticed the arguments are the serverside ones, i edited the OP with the current code.
It should, but it still gives the same error.
So, anyone?
Wait, are you hooking this serverside or clientside?
[editline]01:52PM[/editline]
Clientside, my bad. Can you show us the line of code that sends the table serverside?
Sure, here :
[lua]function ENT:SetData(name,val,force)
if self.NWData[name] == val then
if !force then
DebugPrint("Value \""..name.."\" is the same, not sending.")
return
else
DebugPrint("Value \""..name.."\" is the same, forcing data.")
end
end
self.NWData[name] = val
datastream.StreamToClients(self:GetPlayer(),"Sun_SetShipData",{Name = name,Value = val,Entity = self})
end[/lua]
Instead of sending the entity itself, why don't you just send the Entindex and use ents.GetByIndex() on the client, that way you could use Usermessages, they are much more efficient, and in my experience, reliable.
[QUOTE=MakeR;17023644]Instead of sending the entity itself, why don't you just send the Entindex and use ents.GetByIndex() on the client, that way you could use Usermessages, they are much more efficient, and in my experience, reliable.[/QUOTE]
Usermessages send the entindex.
Usermessage send the entindex?
[QUOTE=MakeR;17023983]Usermessage send the entindex?
Do you mean datastream? if so, i didn't know that.[/QUOTE]
'umsg.Entity' and 'bf_read.ReadEntity' both use the entindex. I'd lose all respect for Valve if they didn't.
Kev, I suggest you use plain usermessages for simple data, like in this case, and use datastream when sending large tables of unknown structure.
I wish i found this out earlier, it would have saved me a few seconds of coding.
I just tried it with usermessages, still the same problem.
Come on, someone has to know.
[QUOTE=kevkev;17024630]I just tried it with usermessages, still the same problem.[/QUOTE]
Post the code.
It should look something like this..
[lua]
function ENT:SetData( key, value, force )
if( self.NWData[ key ] == value and force ) then
return;
end
self.NWData[ key ] = value;
umsg.Start( "SetData", RecipientFilter( ):AddAllPlayers( ) );
umsg.Entity( self );
umsg.String( key );
umsg.String( value );
umsg.End( );
end
local function Msg_SetData( data )
local entity = data:ReadEntity( );
local key = data:ReadString( );
local value = data:ReadString( );
local tbl = entity.NWData or { };
tbl[ key ] = value;
entity.NWData = tbl;
end
usermessage.Hook( "SetData", Msg_SetData );
[/lua]
That is almost exactly my code except for that my code automatically sends different data types (Entity, Angle, Vector, etc.) When i print the variables it even works fine except the table is ALWAYS nil.
Sorry, you need to Log In to post a reply to this thread.