hellolo!
i ve got a question concerning timers in gmod.
im using glsock2 for a udp connection, what i want to do is pretty simple, i just want the data to read only every 0.03 seconds.. if i add the line
[CODE]timer.Create("udptimer", 0.03, 0, socket:ReadFrom( 30, onRead));[/CODE]
gmod accually does what i want, but spams with errors :
[CODE][ERROR] gamemodes/entangledspaces/gamemode/client/udp2angle.lua:91: bad argument #4 to 'Create' (function expected, got boolean)
1. Create - [C]:-1
2. unknown - gamemodes/entangledspaces/gamemode/client/udp2angle.lua:91
3. v - [C]:-1
4. unknown - lua/includes/modules/hook.lua:82
[/CODE]
if i change the arguments as it says in luawiki: [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index9643.html"]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index9643.html[/URL]
[QUOTE]Lua invokes member functions by passing the object as the first parameter to the function.
If you were to call self:SetHealth(100), which can be written as self.SetHealth(self,100), you would create a timer with timer.Create("timer1", 1, 0, self.SetHealth, self, 100).
This would set self's health to 100 every second.[/QUOTE]
gmod crashes
anyone got an idea ?
thanks in advance !
numu
Timers no longer work like that, that is outdated. You must call it like this:
[code]timer.Create("udptimer", 0.03, 0, function() socket:ReadFrom( 30, onRead) end)[/code]
Basically you create and call a function inside the timer, so if you want to do anything you have to format it like this:
[code]
function()
local text = "stuff"
print(text)
end
[/code]
You can also directly call a function like this:
[code]function ReadSocket()
socket:ReadFrom( 30, onRead)
end
timer.Create("udptimer", 0.03, 0, ReadSocket)[/code]
But if you want to call arguments to the function you have to do it by either doing it in a meta fashion like "object:Function" or "function() ReadSocket(onRead) end"
[QUOTE=OzymandiasJ;41861313]Timers no longer work like that, that is outdated. You must call it like this:
[code]timer.Create("udptimer", 0.03, 0, function() socket:ReadFrom( 30, onRead) end)[/code]
Basically you create and call a function inside the timer, so if you want to do anything you have to format it like this:
[code]
function()
local text = "stuff"
print(text)
end
[/code]
You can also directly call a function like this:
[code]function ReadSocket()
socket:ReadFrom( 30, onRead)
end
timer.Create("udptimer", 0.03, 0, ReadSocket)[/code]
But if you want to call arguments to the function you have to do it by either doing it in a meta fashion like "object:Function" or "function() ReadSocket(onRead) end"[/QUOTE]
thanks!
Sorry, you need to Log In to post a reply to this thread.