I’m quite new to Corona and lua but really enjoying exploring a great programming context.
I have a long complex function called “play” which prints short phrases with timed pauses in between - a sort of live instruction feed appearing on the standard output. (I say “long complex function” because it’s not just working it’s way through an array: it has various if-thens, repeat untils/ nested functions)
I’ve tested this and it works fine.
I now want to make it interactive - the user will press various onscreen buttons to affect what is happening.
So I wrote a function called “getCommand” which gathers any commands from buttons and puts them in a buffer. I did this very simply by making each buttons touch event put a different string into a variable lastButton.
When I first ran my updated program, the screen stayed black. I’m guessing that because my program ran “play” which called “getCommand” and “getCommand” was sitting in a loop waiting for something to appear in lastButton, the program never got to processing display refreshes and so the screen stays black.
Does that sound like a plausible explanation?
I come from a Visual Basic Background and in VBA you can use “DoEvents” to give the screen or any other operating system routines some space to do some processing. So I wondered if there was an equivalent in Corona but couldn’t find anything?
So…
I thought one possibility would be to rewrite “play” as a state machine but this would be too complex - I’d end up with loads of functions and loads of setting up and clearing eventlisteners which would be pretty unreadable.
I then found section 9.3 of PiL called “Coroutines as Iterators” and thought great! - whenever “play” needs to get input from a button, use coroutine.yield. And then whenever a button is pressed use coroutine.resume.
Does that sound like a sensible approach?
Or am I missing something about the way corona works?
Just want to check I’m thinking about this in a sensible way.
Any help/guidance would be appreciated.
In particular any documentation/articles about the App lifecycle and how screen refresh/touch handling is interleaved with a running function would be useful.
Thanks
Suhada
[import]uid: 67842 topic_id: 12839 reply_id: 312839[/import]
[import]uid: 3826 topic_id: 12839 reply_id: 47142[/import]