Timer 2.0

What’s New?
Added parameter for choosing time limit
Added new text after time is up
Added parameter max limit: 6 hours


--Here is the update code:

function setup()
    supportedOrientations(LANDSCAPE_ANY)
   q = 0
    parameter.integer("Time", 499, 60000, 499)
    parameter.action("Restart", function() setup() end)
end
function draw()
    background(0, 0, 0, 0)
    fill(255, 0, 0, 255)
       q = q + 1
    fontSize(60)
    text("Timer: " ..q, 400, 700)
    if q >Time then
        q = q -1
        text("TIME UP!", 400, 300)
        fontSize(20)
        text("Tap the restart button to restart", 500, 100)
    end
end

Please keep your program’s development in a single discussion.

I would recommend using DeltaTime instead 1 so the time doesn’t change with the FPS (this will make the timer in seconds, not frames), and making it into a class rather than just plain code.

Also, there’s already a timer in Codea called tween.delay.

Here’s my timer ish count down thingy. You give it the duration and a decimal bool that sets if you want tenths of a second or not. It counts down from the given duration, I use it for stuff like counting down point values. Its not really a timer but just thought I’d share.

-- CountDown

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    timer = CountDown(5, 1)
end

-- This function gets called once every frame

function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    timer:draw()
    timer:RunTimer()
    -- This sets the line thickness
    strokeWidth(5)
    
end

CountDown = class()

function CountDown:init(dur, dec)
    self.dec = dec or false
    self.dur = dur
    self.done = false
    self.runCol = color(51, 184, 44, 255)
    self.doneCol = color(238, 5, 5, 255)
    self.once = false

end

function CountDown:draw()
    pushStyle()
    if self.done == false then
        fill(self.runCol)
        stroke(self.runCol)
    else
        fill(self.doneCol)
        stroke(self.doneCol)
    end
    ellipse(WIDTH/2, HEIGHT/2, 150)

    popStyle()
    pushStyle()
    font("ArialMT")
    fontSize(100)
    fill(0, 0, 0, 255)

    text(string.format("%1.1f",self.dur), WIDTH/2, HEIGHT/2)   
    popStyle()
end

function CountDown:RunTimer()
    if self.dec then
        if self.done ~= true then
            self.dur = self.dur - DeltaTime
        else
            self.dur = 0
        end
    else

        if self.once == false then
            self.tFloorOld = math.floor(ElapsedTime)
            self.once = true 
        end
        
        self.tFloorNew = math.floor(ElapsedTime)     
        
        if self.tFloorNew ~= self.tFloorOld and self.dur ~= 0 then
            self.dur = self.dur - 1
        -- print("Time: ".. self.dur)
            self.tFloorOld = math.floor(ElapsedTime)    
        end   
    end   
    if self.dur <= 0 then
        self.done = true
    end
end

function CountDown:GetDur()
    return self.dur
end

function CountDown:SetDur(dur)
    self.dur = dur
end

function CountDown:GetDoneBool()
    return self.done
end