Name
WaitEvent -- wait for an event to occur
Synopsis
info = WaitEvent()
Function
The WaitEvent() function puts Hollywood in sleep state. The program will be woken up when an event is triggered. In this case WaitEvent() will execute the function that you installed for this event and then it will return. Therefore, you always need to use WaitEvent() in a loop. For example:

 
While quit = False
   WaitEvent
Wend

Or use an endless loop:

 
Repeat
   WaitEvent
Forever

WaitEvent() is a core function of the Hollywood language and you should use one of the loops presented above in every script as your main loop. WaitEvent() has the advantage that it sleeps until an event is triggered. This is important in a multitasking environment because it saves CPU time. Never use polling loops as they will consume all CPU time. If you need to constantly execute code in your main loop, use SetInterval() to install an interval function that gets called 25 times a second by WaitEvent().

The functions that WaitEvent() will call when an event is triggered can be installed with the following functions of the Hollywood event library: MakeButton(), SetInterval(), SetTimeout(), and InstallEventHandler()

Note that WaitEvent() must not be called from any callbacks executed by WaitEvent(). In general, you should use WaitEvent() only once in your script: in your main loop. If you really have to check for events in a callback executed by WaitEvent(), use CheckEvents() instead, but this should normally be unnecessary.

WaitEvent() returns a table that contains information about the callback function it has just executed. The following fields will be initialized in that table:

Action:
Contains the name of the event that caused the callback execution (e.g. OnMouseDown). If WaitEvent() returns without having run a callback, this field will be set to an empty string.

ID:
Contains the identifier of the object that caused the callback execution (e.g. a display identifier). ID can also be zero in case an event was caused that has no identifier associated.

Triggered:
Will be set to True if WaitEvent() has executed a callback and then returned control to the script. If this is set to False, then some other internal event has caused WaitEvent() to return control to the script.

NResults:
Contains the number of values that the user callback returned (e.g. 1). This will be 0 if the user callback did not return any values or if no user callback was ran at all.

Results:
If NResults is greater than 0, this table will contain all values that the user callback returned. Otherwise this table will not be present at all. You can easily use this table to pass additional information from your callbacks back to the main scope of the program.

Inputs
none

Results
info
return values from previously executed event function; normally you won't need this and you can ignore it
Example
See MakeButton
See SetInterval
See SetTimeout
See InstallEventHandler


Show TOC