1
\$\begingroup\$

Pico8 has a function time() that when called displays the current time from start of program.
i.e. print(time(),0,0,14) --prints time at (0,0) with colour 14

However the function doesn't stop and keeps drawing the time each frame. I'm trying to figure out how I would draw the time without it increasing/changing. So If I printed this 5 seconds from the start of the program I'd want it to display 5, but not change from that 5 value.

https://pico-8.fandom.com/wiki/Time I don't know how to store a static value of this time as a variable. Although according to the wiki, assigning var=time() will cause time at 0 to be stored.

Another way of phrasing this is...how would I display the time of 10 seconds when the following print is triggered? So after 10 seconds "time's up" is displayed. How would I display the current time 10, as well, as a static? Maybe I don't know what the time is when the event is triggered, so how can I count using time()?

function _init()
  last = time()
end

function _update()
  -- (empty update to use game loop)
end

function _draw()
  cls()
  if (time() - last) > 10 then
    print("time's up!", 44, 60, 7)
  end
end
\$\endgroup\$
  • \$\begingroup\$ I think you should be able to initialize a variable at 0, then on the callback you can check if it is 0, and if it is, set the time. I am not entirely familiar with Lua. \$\endgroup\$ – Theraot Jul 22 at 23:46
0
\$\begingroup\$

I'm not sure what exactly are you trying to achieve, but maybe something like this?

local start
local limit = 10
local finish

function _init()
  start = time()
end

function _draw()
  cls()
  local now = time()
  local delta = now - start
  if delta >= limit then
    -- time's up
    print("time's up!", 44, 60, 7)
    -- saving timestamp
    if finish == nil then
      finish = now
    end
  else
    -- still ticking
    print(delta, 44, 60, 7)
  end
end
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.