KillTimer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(OOP syntax added)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
This function allows you to kill/halt existing timers, by passing a timerID as a parameter.
__NOTOC__
This function allows you to kill/halt existing timers.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool killTimer ( timerID )
bool killTimer ( timer theTimer )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[timer]]:destroy||}}
===Required Arguments===  
===Required Arguments===  
*'''timer:''' The timer you wish to halt.
*'''theTimer:''' The [[timer]] you wish to halt.


===Returns===
===Returns===
Returns ''true'' if the timer was existing and killed, ''false'' if not.
Returns ''true'' if the timer was successfully killed, ''false'' if no such timer existed.


==Example==  
==Example==  
'''Example 1:'' This example will kill an existing timer.
This example kills all timers with a remaining time of less than 1 minute.
<syntaxhighlight lang="lua">
-- Find and kill all the timers with less than 1 minute to go
timers = getTimers ( 60000 )
-- Loop through the timer list
for timerKey, timerValue in ipairs(timers) do
-- kill the timer
      killTimer ( timerValue )
end
</syntaxhighlight>


This example checks if the time then kill the timer.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
timer = setTimer ( "delayedChat", 1000, 1, "Hello, World!" )
-- set timer output text in chat box
killTimer ( timer )
local Timer = setTimer ( function ( ) outputChatBox ( 'Hello World !' ) end, 60000, 0 )
-- Check the timer then kill the timer
if isTimer ( Timer ) then killTimer ( Timer ) end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}
[[Category:Needs_Checking]]

Latest revision as of 07:01, 12 July 2014

This function allows you to kill/halt existing timers.

Syntax

bool killTimer ( timer theTimer )

OOP Syntax Help! I don't understand this!

Method: timer:destroy(...)


Required Arguments

  • theTimer: The timer you wish to halt.

Returns

Returns true if the timer was successfully killed, false if no such timer existed.

Example

This example kills all timers with a remaining time of less than 1 minute.

-- Find and kill all the timers with less than 1 minute to go
timers = getTimers ( 60000 )
-- Loop through the timer list
for timerKey, timerValue in ipairs(timers) do
	-- kill the timer
      killTimer ( timerValue )
end

This example checks if the time then kill the timer.

-- set timer output text in chat box
local Timer = setTimer ( function ( ) outputChatBox ( 'Hello World !' ) end, 60000, 0 )
-- Check the timer then kill the timer
if isTimer ( Timer ) then killTimer ( Timer ) end

See Also