glowdemon1 Posted September 3, 2013 Posted September 3, 2013 Hi, my suggestion is to implement a simple sleep(time) function, this can be used to delay something in your functions, for instance : outputChatBox("I have waited 0 seconds") sleep(10000) -- Sleep in ms. outputChatBox("I have waited 10 seconds") I dislike the fact that I have to add timers and such which will eventualy make your code a mess. MySQL based MP3 System - unique radio stations My mappings
DiSaMe Posted September 3, 2013 Posted September 3, 2013 http://www.lua.org/manual/5.1/manual.html#2.11 http://www.lua.org/manual/5.1/manual.html#5.2 -
xXMADEXx Posted September 4, 2013 Posted September 4, 2013 Whats wrong with setTimer? The Ultimate Lua Tutorial! | MTA PHP SDK
glowdemon1 Posted September 4, 2013 Author Posted September 4, 2013 I dislike the fact that I have to add timers and such which will eventualy make your code a mess. sleep() would be much easier, a more compact code and so on. MySQL based MP3 System - unique radio stations My mappings
ixjf Posted September 4, 2013 Posted September 4, 2013 Then write it. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
glowdemon1 Posted September 5, 2013 Author Posted September 5, 2013 I would, only if I were capable to. MySQL based MP3 System - unique radio stations My mappings
DiSaMe Posted September 5, 2013 Posted September 5, 2013 (edited) function callFunctionWithSleeps(calledFunction, ...) local co = coroutine.create(calledFunction) --we create a thread coroutine.resume(co, ...) --and start its execution end function sleep(time) local co = coroutine.running() local function resumeThisCoroutine() --since setTimer copies the argument values and coroutines cannot be copied, co cannot be passed as an argument, so we use a nested function with co as an upvalue instead coroutine.resume(co) end setTimer(resumeThisCoroutine, time, 1) --we set a timer to resume the current thread later coroutine.yield() --we pause the execution, it will be continued when the timer calls the resume function end -----------example----------- function pauseExample(a, b, c) outputChatBox("Started the execution. a value: "..tostring(a)) sleep(5000) outputChatBox("Waited 5 seconds. b value: "..tostring(b)) sleep(5000) outputChatBox("Waited 10 seconds, finishing the execution. c value: "..tostring(c)) end callFunctionWithSleeps(pauseExample, 1, 2, 3) Not tested, but should work. Keep in mind, however, that this exact implementation won't display errors within the called function, because coroutine.resume returns the error as a string instead of propagating it to the caller. Edited September 8, 2013 by Guest 3 -
Recommended Posts