ResetTimer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(I've tested many timers that have a limited number of repeats with a range of 5,000 ms and a limited repeat of 1 time, and it works, so it can lead many people astray.)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
__NOTOC__
__NOTOC__
This function allows you to reset the elapsed time in existing timers to zero. The function does not reset the 'times to execute' count on timers which have a limited amout of repetitions.
This function allows you to reset the value of the elapsed time in existing timers. The function resets the "execution time" value for timers with a limited number of repetitions.


==Syntax==  
==Syntax==  
Line 7: Line 7:
bool resetTimer ( timer theTimer )
bool resetTimer ( timer theTimer )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[timer]]:reset||}}
===Required Arguments===  
===Required Arguments===  
*'''theTimer:''' The [[timer]] whose elapsed time you wish to reset.
*'''theTimer:''' The [[timer]] whose elapsed time you wish to reset.
Line 16: Line 16:
==Example==  
==Example==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local timer = setTimer(example,3000,1)
-- This example shows how you can reset timer by using /rtimer command.
 
local timerElement = false
 
function timerFunction()
print("Timer function executed at "..getTickCount())
end
timerElement = setTimer(timerFunction, 3000, 0)
 
function timerResetCommand()
local validTimer = isTimer(timerElement)


function example()
if validTimer then
  outputChatBox("3 seconds has passed.")
print("Timer has been resetted.")
  resetTimer(timer)
resetTimer(timerElement)
end
end
end
addCommandHandler("rtimer", timerResetCommand)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}

Latest revision as of 09:15, 24 August 2025

This function allows you to reset the value of the elapsed time in existing timers. The function resets the "execution time" value for timers with a limited number of repetitions.

Syntax

bool resetTimer ( timer theTimer )

OOP Syntax Help! I don't understand this!

Method: timer:reset(...)


Required Arguments

  • theTimer: The timer whose elapsed time you wish to reset.

Returns

Returns true if the timer was successfully reset, false otherwise.

Example

-- This example shows how you can reset timer by using /rtimer command.

local timerElement = false

function timerFunction()
	print("Timer function executed at "..getTickCount())
end
timerElement = setTimer(timerFunction, 3000, 0)

function timerResetCommand()
	local validTimer = isTimer(timerElement)

	if validTimer then
		print("Timer has been resetted.")
		resetTimer(timerElement)
	end
end
addCommandHandler("rtimer", timerResetCommand)

See Also