Log In  

Hi, I made a pause/wait function. Feel free to use.

timer=1
p=0

function _update()
 pause(5)--Wait 5/30 frames then do what is in the if loop
 if timer==1 then
 end
end

function pause(p)
 if timer>p then
  timer=0
 end
 timer+=1
end

Cart #nafipoyede-0 | 2021-08-06 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

P#95724 2021-08-06 19:14 ( Edited 2021-08-06 19:18)

That’s neat!

I was thinking that it’s a bit messy that the functions that use 'pause' also need to check 'timer'. What if 'pause' returned a boolean to let the _update function decide whether to return or continue?

P#95792 2021-08-09 01:37

or having support for multiple timers:

function pause(t0,autoreset)
 local t=t0
 return function()
  t-=1
  if t==0 then
   if(autoreset) t=t0
   return true
  end
 end
end

— new timer
t1=pause(5,true)
t2=pause(10)
function _update()
 if t1() then
  printh(“do something (and again)“)
 end

 if t2() then
  printh(“do another thing :)”)
 end
end
P#95798 2021-08-09 07:34 ( Edited 2021-08-09 07:36)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 22:15:25 | 0.020s | Q:15