Jump to content

BlitzMax/Modules/Events/Event queue

From Wikibooks, open books for an open world

The event queue is a simple first-in, first-out queue that is used to collect TEvent objects emitted by your application.

The PollEvent and WaitEvent commands can be used to receive the next event from the event queue, while the PeekEvent command can be used to check if the event queue is empty.

Events are added to the event queue using PostEvent.

Globals

[edit | edit source]

CurrentEvent

[edit | edit source]

Global CurrentEvent:TEvent=NullEvent

Description: Current Event

Information: The CurrentEvent global variable contains the event most recently returned by PollEvent or WaitEvent.

Functions

[edit | edit source]

PeekEvent

[edit | edit source]

Function PeekEvent:TEvent()

Description: Examine the next event in the event queue

Information: PeekEvent examines the next event in the event queue, without removing it from the event queue or modifying the CurrentEvent global variable.

If there are no events in the event queue, PeekEvent returns Null.

PollEvent

[edit | edit source]

Function PollEvent()

Description: Get the next event from the event queue

Returns: The id of the next event in the event queue, or 0 if the event queue is empty

Information: PollEvent removes an event from the event queue and updates the CurrentEvent global variable.

If there are no events in the event queue, PollEvent returns 0.

WaitEvent

[edit | edit source]

Function WaitEvent()

Description: Get the next event from the event queue, waiting if necessary

Returns: The id of the next event in the event queue

Information: WaitEvent removes an event from the event queue and updates the CurrentEvent global variable.

If there are no events in the event queue, WaitEvent halts program execution until an event is available.

PostEvent

[edit | edit source]

Function PostEvent( event:TEvent,update=False )

Description: Post an event to the event queue

Information: PostEvent adds an event to the end of the event queue.

The update flag can be used to update an existing event. If update is True and an event with the same id and source is found in the event queue, the existing event will be updated instead of event being added to the event queue. This can be useful to prevent high frequency events such as timer events from flooding the event queue.

EventID

[edit | edit source]

Function EventID()

Description: Get current event id

Returns: The id field of the CurrentEvent global variable

EventData

[edit | edit source]

Function EventData()

Description: Get current event data

Returns: The data field of the CurrentEvent global variable

EventMods

[edit | edit source]

Function EventMods()

Description: Get current event modifiers

Returns: The mods field of the CurrentEvent global variable

EventX

[edit | edit source]

Function EventX()

Description: Get current event x value

Returns: The x field of the CurrentEvent global variable

EventY

[edit | edit source]

Function EventY()

Description: Get current event y value

Returns: The y field of the CurrentEvent global variable

EventExtra

[edit | edit source]

Function EventExtra:Object()

Description: Get current event extra value

Returns: The extra field of the CurrentEvent global variable

EventText

[edit | edit source]

Function EventText$()

Description: Get current event extra value converted to a string

Returns: The extra field of the CurrentEvent global variable converted to a string

EventSource

[edit | edit source]

Function EventSource:Object()

Description: Get current event source object

Returns: The source field of the CurrentEvent global variable

EventSourceHandle

[edit | edit source]

Function EventSourceHandle()

Description: Get current event source object handle

Returns: The source field of the CurrentEvent global variable converted to an integer handle