It looks like you're new here. If you want to get involved, click one of these buttons!
Hi, here is a simple pause function I made :
-- TEST
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
wait = 5
i = 0
end
function sectoframes(sec)
return sec * 60
end
function frametosec(frame)
return frame / 60
end
function pause(wait)
if frametosec(i) < wait then
i = i + 1
return 0
end
if i == sectoframes(wait) then
return 1
end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
pausenumber = pause(5)
if pausenumber == 1 then
text("ok", WIDTH/2, HEIGHT - 100)
elseif pausenumber == 0 then
text("wait", WIDTH/2, HEIGHT - 100)
else
text("error", WIDTH/2, HEIGHT - 100)
end
end
What do you think about it ?
Comments
Hello @eloi67. If you made use of
ElapsedTime
to keep track of the passage of time, then you would not need to count frames (or assume a constant frame rate of 60 per second).By using the
arg
feature of Lua, thepause
function could do two things:(1) called with an argument, it could set the duration of the next pause (if it is not already waiting); and
(2) called with no arguments, it could only return whether or not it is waiting.
For example (touch the viewer for a two-second wait):
hello. I have found the following function in the forum. I use it in my pushball game, it works very well, once i understood the syntax to pass the callback function. It is not exactly a pause() function, but the usage of a pause function is to start something after the pause, exactly what this timer does.
If you're after a pause for a game or anything else, then this is pretty simple. But running this leads to a question I have about the draw function. When I run this and hit pause, I constantly show 3 numbers during the pause even though I only draw 1 number per draw cycle. It doesn't matter how fast or slow I hit pause. Is there a 3 screen buffer being drawn during each draw cycle.
If I add another text line, then I see 6 numbers during the pause. I was expecting to see 1 number per text line, not 3.
Yes.
I took my pause program one step further by adding pause=true after the text statement. So basically I'm pausing after each draw cycle. Looking at the numbers that are displayed, I see that:
1.) There are 3 screen buffers that I saw earlier.
2.) The buffers don't change in a regular pattern. Some of the buffers stay around for up to 8 cycles, while other buffers stay for 1 cycle. Interesting how the draw function works.