SetTimer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 6: Line 6:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
timerID setTimer ( string functionName, int time, int timesToExecute, [var argument1, ...] )
timerID setTimer ( function theFunction, int timeInterval, int timesToExecute, [var argument1, ...] )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''functionName:''' The name of the function you wish the timer to call.
*'''theFunction:''' The function you wish the timer to call.
*'''time:''' The number of milliseconds that should ellapse before the function is called. 1000 milliseconds = 1 second.
*'''timeInterval:''' The number of milliseconds that should ellapse before the function is called. 1000 milliseconds = 1 second.
*'''timesToExecute:''' The number of times you want the timer to execute. 0 = infinite.
*'''timesToExecute:''' The number of times you want the timer to execute. 0 = infinite.


Line 33: Line 33:
Then we can set a timer that will call it in 1 second (1000 milliseconds) time.
Then we can set a timer that will call it in 1 second (1000 milliseconds) time.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
setTimer ( "delayedChat", 1000, 1, "Hello, World!" )
setTimer ( delayedChat, 1000, 1, "Hello, World!" )
</syntaxhighlight>
</syntaxhighlight>
1 second after the line above has been executed, the text ''Delayed text: Hello, World!'' will be displayed in the chat box.
1 second after the line above has been executed, the text ''Delayed text: Hello, World!'' will be displayed in the chat box.
Line 39: Line 39:
==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}
[[Category:Needs_Checking]]

Revision as of 19:55, 28 June 2007

This function allows you to trigger a function after a number of milliseconds have ellapsed. You can call either your own functions, or built in functions. For example, you could set a timer to spawn a player after a number of seconds had ellapsed.

Once a timer has finished repeating, it no longer exists.

Syntax

timerID setTimer ( function theFunction, int timeInterval, int timesToExecute, [var argument1, ...] )

Required Arguments

  • theFunction: The function you wish the timer to call.
  • timeInterval: The number of milliseconds that should ellapse before the function is called. 1000 milliseconds = 1 second.
  • timesToExecute: The number of times you want the timer to execute. 0 = infinite.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • argument1: Any arguments you wish to pass to the function can be listed after the repeats variable.

Returns

Returns timerID if the timer was set succesfully, false if the arguments are invalid or the timer could not be set.

Example

This example will output some text after a number of seconds.

First we define a function that we wish to be called.

function delayedChat ( text )
	outputChatBox ( "Delayed text: " .. text )
end

Then we can set a timer that will call it in 1 second (1000 milliseconds) time.

setTimer ( delayedChat, 1000, 1, "Hello, World!" )

1 second after the line above has been executed, the text Delayed text: Hello, World! will be displayed in the chat box.

See Also