ok I'm a total noob at Lua so if someone can point out my stupid mistake I'd be grateful!
I wrote a simple delay function to basically do-nothing for a given period of time. I've placed a call to my delay function in between 3 different function calls. But it doesn't seem to delay in between each function - instead it still seems to call all 3 functions AFTER waiting the combined amount of delay of time. Here is my delay function:
function delay(seconds)
local startTime = os.timer()
while (os.timer() - startTime) < seconds do
--Nothing
end
end
And here is how I am trying to use it:
callFunction1()
delay(5)
callFunction2()
delay(5)
callFunction3()
But what seems to happen is the system waits 10 seconds and THEN calls all 3 functions.
Is there a better way of doing this? I know about timers but they seem to be set up to call the SAME function at set intervals which isn't quite what I want.
Thanks
Comments
Anyway I think delayedCall is perfect for what you are looking for? http://www.giderosmobile.com/documentation/reference_manual.html#Timer.delayedCall
1. Have a timer and chain all of your functions to run one after the other
2. Create a queue that processes/chains your functions one after the other
3. Have a blocking call that waits till that time is up, but the problem with that is everything else freezes.
4. Once we get sockets, use a socket timeout to delay execution for that duration.
5. calling the delayed call as suggested by @avo
Please note that the order of the suggestions is not in any particular order, it's just my approach to how I would have tried to resolve this.
The way lua works, there is no loop for ever and a doEvents() to catch your breath. The closest thing to that is coroutines, but then you will need a near endless loop to keep that going.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
However now that you have confirmed that I wasn't doing something crazy I shall reconsider DelayedCall.
Many thanks.
To implement a delay function like you requested I'd just have a "delay" state which when entered would set a counter for the number of frames to "delay" and then when that number of frames have passed, I'd move to the next state (again this would normally be setup prior to entering the delay state).
If you need something more flexible you could probably use a table like a kind of timeline script, where by you could have a delay counter and then a reference the function that you call next which you could then walk through in some kind of master loop timeline parsing function.
Hope I haven't confused you too much (it's still early here and I haven't had a cuppa yet! )
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
It is such a small feature I wouldn't want to "pollute" my main finite state machine with a state just for adding buttons so I was hoping for a more elegant approach that was self-contained within my Menu class
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill