Global Command: setDelay

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 01:11, 3 May 2023 by EK (talk | contribs) (Created page with "Executes a function with a delay. == Syntax == <syntaxhighlight lang="lua"> setDelay(time, callback) </syntaxhighlight> == Parameters == {| class="ts" |- ! style="width:1...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Executes a function with a delay.


Syntax

setDelay(time, callback)


Parameters

Parameter Type Description
time integer Time to wait until the callback function gets executed (in milliseconds).
callback function/string Callback function to execute.


Return values

none


Examples

Example 1: Different ways of printing "Hello World" with a delay of 1 second.

function helloWorld()
  print("Hello World")
end

-- Call the "helloWorld()" function
setDelay(1000, "helloWorld()")

-- Another way to call the "helloWorld()" function
setDelay(1000, helloWorld)

-- Use an anonymous function as the second argument
setDelay(1000, function() print("Hello World") end)