Log In  

I'm trying to make a little intro and i can't figure out how to do a delay, I just need to delay for a couple of milliseconds, that's all.

thanks!

P#47391 2017-12-14 21:50 ( Edited 2017-12-15 06:51)

2

You can either use coroutines or a timer pattern, see the sample I posted on another thread:

-- global time
time_t=0
actors={}
for i=1,32 do
 add(actors,{t=rnd(90),visible_t=0,x=rnd(128),y=rnd(128)})
end
function _update()
 time_t+=1
 for a in all(actors) do
  -- timer elapsed?
        if a.t<time_t then
         -- visible for some time
            a.visible_t=time_t+rnd(30)
            -- "think" time
            a.t=a.visible_t+rnd(90)
        end
 end
end
function _draw()
 cls()
 for a in all(actors) do
  if a.visible_t>time_t then 
        print("-o-",a.x,a.y,7)
     else
        print("---",a.x,a.y,1)
     end
 end
end
P#47394 2017-12-15 01:48 ( Edited 2017-12-15 06:48)
2

Each update is 1/30th of a second (unless you use _update60(), in which case it's 1/60th of a second). So you can just make a counter that counts down from however many frames you want to delay, then when it gets to 0, do whatever is next. That's the "swing a big, fat hammer at it" approach.

The "use a scalpel" approach is to use "coroutines" to delay whatever action should happen next. But that's a much longer answer.

EDIT: Or just follow the example that @freds72 helpfully posted while I was typing my reply. :D

P#47395 2017-12-15 01:51 ( Edited 2017-12-15 06:52)

[Please log in to post a comment]