Timers
(Difference between revisions)
(Created page with "Some small snippets about timers, You can just copy/paste them in your script, results will be displayed in the maratis console window ----- ===== Basic Timer ===== ----- ...") |
Dahnielson (Talk | contribs) m |
||
| Line 2: | Line 2: | ||
You can just copy/paste them in your script, | You can just copy/paste them in your script, | ||
results will be displayed in the maratis console window | results will be displayed in the maratis console window | ||
| − | |||
| − | + | === Basic Timer === | |
| − | + | ||
t = 0 | t = 0 | ||
function onSceneUpdate() | function onSceneUpdate() | ||
| Line 11: | Line 10: | ||
print(t) | print(t) | ||
end | end | ||
| − | |||
| − | + | === Basic Timer + Action === | |
| − | + | ||
t = 0 | t = 0 | ||
function onSceneUpdate() | function onSceneUpdate() | ||
| Line 24: | Line 22: | ||
end | end | ||
end | end | ||
| − | |||
| − | + | === Count Seconds === | |
| − | + | ||
ms = 0 | ms = 0 | ||
seconds = 0 | seconds = 0 | ||
| Line 38: | Line 35: | ||
end | end | ||
end | end | ||
| − | |||
| − | + | === Start/Stop timer on key press === | |
| − | + | ||
timestart = false | timestart = false | ||
t = 0 | t = 0 | ||
| Line 57: | Line 53: | ||
end | end | ||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
[[Category:User manual]] | [[Category:User manual]] | ||
[[Category:Lua scripting]] | [[Category:Lua scripting]] | ||
Revision as of 16:15, 11 February 2014
Some small snippets about timers, You can just copy/paste them in your script, results will be displayed in the maratis console window
Contents |
Basic Timer
t = 0
function onSceneUpdate()
t = t + 1 -- count + 1 every frames
print(t)
end
Basic Timer + Action
t = 0
function onSceneUpdate()
t = t + 1
if t == 120 then
print("2 seconds")
t = 0 -- reset timer to 0, so it will loop forever
-- do something else here
end
end
Count Seconds
ms = 0
seconds = 0
function onSceneUpdate()
ms = ms + 1
if ms == 60 then
seconds = seconds + 1
ms = 0
print(seconds, "<- Seconds")
end
end
Start/Stop timer on key press
timestart = false
t = 0
function onSceneUpdate()
if onKeyDown("SPACE") and timestart == false then
timestart = true
print("START")
elseif onKeyDown("SPACE") and timestart == true then
timestart = false
print("STOP")
end
if timestart == true then
t = t + 1
print(t, "<- time")
end
end