ResetTimer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(OOP syntax added)
(Fix & improve example.)
Line 16: Line 16:
==Example==  
==Example==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local timer = setTimer(example,3000,1)
-- This example allows you to reset timer by using /rtimer command.


function example()
local timerElement = false
  outputChatBox("3 seconds has passed.")
 
  resetTimer(timer)
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
end
addCommandHandler("rtimer", timerResetCommand)
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 06:30, 30 June 2022

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.

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 allows you to 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