is there a "wait for event" mechanism in Corona?

Hi Corona folks,

I’m trying to develop my own RPG game, and got stuck in a very simple issue. I’m running a script in the game, which displays the lines of a dialog one by one, and the player could click on the screen to see the next line. Like below:

gameText("This is a small room") -- blocked, wait for click event gameText("There's nothing special inside") -- blocked, wait for click event  

So in corona, is there a way of blocking the current thread, waiting until an event (or a signal) has arrived, and continue running?

Many thanks in advance.

Hi @zzk2006,

Corona already includes an event-driven methodology. For your situation, you need to set up events, and also functions which “listen” for those events (known collectively as “listeners”). So, in your case, clicking the text would trigger an event, and send a response to the associated listener function, which would then perform some action (like printing out the next line of text, which would in turn await clicking upon, and so forth).

This guide on basic events and listeners should help you get started:

http://docs.coronalabs.com/guide/events/detectEvents/index.html

Best regards,

Brent Sorrentino

Thanks for the reply!

Hi @zzk2006,

Corona already includes an event-driven methodology. For your situation, you need to set up events, and also functions which “listen” for those events (known collectively as “listeners”). So, in your case, clicking the text would trigger an event, and send a response to the associated listener function, which would then perform some action (like printing out the next line of text, which would in turn await clicking upon, and so forth).

This guide on basic events and listeners should help you get started:

http://docs.coronalabs.com/guide/events/detectEvents/index.html

Best regards,

Brent Sorrentino

Thanks for the reply!