2DWorlds Forums
Does anyone actually need to use sleep() in an event handler? - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4)
+--- Forum: Scripting (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=13)
+--- Thread: Does anyone actually need to use sleep() in an event handler? (/showthread.php?tid=6678)



Does anyone actually need to use sleep() in an event handler? - Jacob__mybb_import1 - 07-08-2011

Disabling sleep() in events would solve a whole lot of issues and confusing things about scripting (having to use gameConfusedcheduleTask() when creating a model from an event handler, for example), but I don't want to do it anyone needs it.

If you just need to disable a tool for an amount of time after a player uses it, using os.time() works just as well. This is the way Buildism and most other games handle this type of thing internally--using sleep() adds an extra thread that does nothing.

[lua]lastClickTime = os.time()
function mouseDown()
if os.time() - lastClickTime < 3 then return end --3 seconds
[...]
lastClickTime = os.time()
end[/lua]


RE: Does anyone actually need to use sleep() in an event handler? - Login - 07-08-2011

gameConfusedcheduleTask() - What exactly does this signify? I'm on my way to learning Lua to help people in Scripting section ^^


RE: Does anyone actually need to use sleep() in an event handler? - Duck - 07-08-2011

I always use sleep.


RE: Does anyone actually need to use sleep() in an event handler? - Jacob__mybb_import1 - 07-08-2011

(07-08-2011, 06:37 PM)Login Wrote: gameConfusedcheduleTask() - What exactly does this signify? I'm on my way to learning Lua to help people in Scripting section ^^

I explained it here: http://buildism.net/forum/Thread-I-m-having-issues-with-descendants-of-UIs?pid=40294#pid40294


RE: Does anyone actually need to use sleep() in an event handler? - Blandflakes - 07-08-2011

I always use sleep :3


RE: Does anyone actually need to use sleep() in an event handler? - Jacob__mybb_import1 - 07-08-2011

I'm not asking if you use it right now, I'm asking if you can do without it. It would solve a lot of problems.


RE: Does anyone actually need to use sleep() in an event handler? - Blandflakes - 07-09-2011

(07-08-2011, 09:16 PM)Jacob_ Wrote: I'm not asking if you use it right now, I'm asking if you can do without it. It would solve a lot of problems.

I could switch if it makes things easier Tongue