Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help with waiting

edited July 2013 in Questions Posts: 23

Is there any way in codea to do a wait or delay function or command? I know that most big programming languages like C/C++ have them, and it would be a real help to me if there was one.



  • BriarfoxBriarfox Mod
    Posts: 1,542

    There is but you have to write it yourself. Here is a timer example by Zoyt. It should give you a general idea.

    --# Main -- Timer Example -- Use this function to perform your initial setup function setup() timer1 = Timer(2,callback) end -- This function gets called once every frame function draw() -- This sets a dark background color background(40, 40, 50) timer1:update() -- This sets the line thickness strokeWidth(5) -- Do your drawing here end function callback() print("This function is called every 2 seconds") end --# Timer --Timer by Zoyt via Codea Forums Timer = class() function Timer:init(interval,callback) self.interval = interval self.callback = callback self.diffTime = 0 self.time = 0 self.occurances = 0 end function Timer:update() self.time = ElapsedTime - self.diffTime if self.time >= self.interval then self.occurances = self.occurances + 1 self.diffTime = ElapsedTime self.time = 0 if type(self.callback) == "function" then self.callback(self.occurances) end return true else return false end end
  • IgnatzIgnatz Mod
    edited July 2013 Posts: 5,396

    I tend to use simpler timers,
    eg set t=0 in set up, then in draw I put
    t=t + DeltaTime --adds time since last redraw
    if t>DelayTime then --etc

    if you want to wait until a job is finished, you need coroutines. I explain how to use them for this, here

  • tween.delay can be useful

Sign In or Register to comment.