Hi. I've been trying to get datastream running. Because I want to send a list of all maps on the server, umsg is complaining the message is too big, and so it fails. My problem now is, when I try to use datastream on the client, it says it's a nil value:
[code]sh_mapslist.lua:53: attempt to index global 'datastream' (a nil value)[/code]
Here is the code:
On the server:
[lua] local Maps = {}
local Gamemodes = {}
local files = file.Find( "../maps/*.bsp" )
for _, filename in pairs( files ) do
table.insert( Maps, filename)
end
local folders = file.FindDir("../gamemodes/*")
for _, foldername in pairs( folders ) do
table.insert(Gamemodes, foldername)
end
local function SendMaps( ply )
datastream.StreamToClients( ply, "sendmaps", { Maps, Gamemodes } )
end
hook.Add("PlayerInitialSpawn","SendMaps",SendMaps)[/lua]
On the client:
[lua] local Maps = {}
local Gamemodes = {}
datastream.Hook( "sendmaps", function( handler, id, encoded, decoded ) -- (<- line 53)
Maps = decoded[1]
Gamemodes = decoded[2]
end)[/lua]
Put require('datastream') at the top of both.
Allright ignore this. Overv helped me through Steam Chat.
The fix is:
[code]if !datastream then require"datastream" end[/code]
people who omit parens (()) around a parameter list should be shot.
if not datastream then require("datastream") end
Question, is the "if not datastream" an important thing to do? I myself have never had an issue with re-requiring.
[QUOTE=Skapocalypse;19778880]Question, is the "if not datastream" an important thing to do? I myself have never had an issue with re-requiring.[/QUOTE]
No it's completely redundant. The require function takes care of it. (That's actually the whole point of 'require' to begin with)
an unconditional require("datastream") will overwrite all changes made by others.
someone might want to work around one of the numerous bugs garry is too lazy to commit fixes for.
Sorry, you need to Log In to post a reply to this thread.