SetTimer: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This function allows you to trigger a function after a number of milliseconds have | {{Server client function}} | ||
This function allows you to trigger a function after a number of milliseconds have elapsed. You can call one of your own functions or a built-in function. For example, you could set a timer to spawn a player after a number of seconds have elapsed. | |||
Once a timer has finished repeating, it no longer exists. | Once a timer has finished repeating, it no longer exists. | ||
Line 13: | Line 14: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theFunction:''' The function you wish the timer to call. | *'''theFunction:''' The function you wish the timer to call. | ||
*'''timeInterval:''' The number of milliseconds that should | *'''timeInterval:''' The number of milliseconds that should elapse 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. | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''argument1:''' Any arguments you wish to pass to the function can be listed after the ''repeats'' | *'''argument1:''' Any arguments you wish to pass to the function can be listed after the ''repeats'' argument. | ||
===Returns=== | ===Returns=== | ||
Line 24: | Line 25: | ||
==Example== | ==Example== | ||
This example will output some text after a | This example will output some text after a small delay. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Define function to be called | |||
function delayedChat ( text ) | function delayedChat ( text ) | ||
outputChatBox ( "Delayed text: " .. text ) | outputChatBox ( "Delayed text: " .. text ) | ||
end | end | ||
-- Set a timer so the function is called after 1 second | |||
setTimer ( delayedChat, 1000, 1, "Hello, World!" ) | setTimer ( delayedChat, 1000, 1, "Hello, World!" ) | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 20:14, 15 August 2007
This function allows you to trigger a function after a number of milliseconds have elapsed. You can call one of your own functions or a built-in function. For example, you could set a timer to spawn a player after a number of seconds have elapsed.
Once a timer has finished repeating, it no longer exists.
The minimum accepted interval is 50ms.
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 elapse 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 argument.
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 small delay.
-- Define function to be called function delayedChat ( text ) outputChatBox ( "Delayed text: " .. text ) end -- Set a timer so the function is called after 1 second 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
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace