ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. waitForEvent

Function

waitForEvent

Server and clientTimersTrilogy Hub only

Pauses an async task until an event happens. Returns the event's source element and its arguments. With a time limit it returns false if the event did not happen in time. The handler and the limit timer are removed when the wait ends.

Syntax

element, ... waitForEvent(string eventName [, element attachedTo = root, int timeoutMs = nil])

Arguments

eventNamestring
The event name.
attachedToelement, optional = root
The element to listen on (with its children).
timeoutMsint, optional = nil
Time limit in ms; without it waits forever.

Returns

The source and the event arguments, or false on timeout.

Example

addCommandHandler("wyzwanie", function(player)
    async(function()
        outputChatBox("Masz 10 sekund, żeby wejść do auta!", player)
        local who = waitForEvent("onPlayerVehicleEnter", player, 10000)
        if who then
            outputChatBox("Udało się!", player)
        else
            outputChatBox("Za późno.", player)
        end
    end)
end)

See also