Howdy, Stranger!

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

Time issues: milliseconds

edited July 2014 in Questions Posts: 35

I know Codea is limited knowing the accurate time in milliseconds, is there a workaround?

Maybe if Codea knows real time in seconds, a program could "learn" to calculate when the next second is coming in...
The "EslapsedTime" is deprecated?

Comments

  • edited July 2014 Posts: 35

    I am dumb.... Weeks figuring why.... Is ElapsedTime... Not ESlapsedTime....

    [/Thread]

  • Posts: 135

    Codea measures in frames (60 frames per second) so that can be used to figure out when the next second is coming

  • dave1707dave1707 Mod
    Posts: 7,915

    @Doge The speed of draw() varies depending on the amount of objects are on the screen. So frames vary from 60 FPS to below 1 FPS, which make it useless for accurate time.

  • Posts: 456

    There's also the os time functions which can be used for more accurate timings.

  • dave1707dave1707 Mod
    Posts: 7,915

    os.clock() will give you CPU time in fractions of a second. If you need a quick time difference, that might work. os.time() will give you seconds and should be use over a longer time period.

  • Posts: 35

    i managed to sync a flashing image to a music's beat, the sync would not be lost but the accuracy is medium... I will post an example...

  • Posts: 35

    Here an example of music sync:

     -- Syncing Test
    
    function setup()
        music("A Hero's Quest:Battle",1)
        isrestarted=readGlobalData("restarted",false)
        bpm=105
        beattime=60/bpm
        beatcount=1
        starttime=ElapsedTime
        delay=0.05
        parameter.watch("ElapsedTime")
        parameter.watch("beatcount")
        parameter.boolean("SomeOverload")
        parameter.boolean("LotOfCalcs")
        currentcolor=0
    end
    
    
    function draw()
        background(0,currentcolor,0)
        if currentcolor>4 then
            currentcolor = currentcolor - 4
        end
        if ElapsedTime>=starttime+(beattime*beatcount) + delay then
            beatcount = beatcount + 1
            currentcolor=70
        end
        if isrestarted==false then
            saveGlobalData("restarted",true)
            text("Please for correct sync press restart now.",300,10)
        end
        if SomeOverload==true then
            sprite(CAMERA,WIDTH/2,HEIGHT/2,200,200)
        end
        if LotOfCalcs==true then
            for i=1, 30000 do
                a=math.log10(i)*math.tan(i)
            end
        end
    end
    
Sign In or Register to comment.