New PICO-8 programmer and relatively new programmer in general.
I'm making a very simple "pong" game just to get the hang of PICO-8 and Lua, but I can't figure out how to start a game paused. I considered setting a variable "paused" and flip it between 0 and 1 using keyboard input (and then running the update functions when paused = 0), but then it would have to be the Z or X key which I might use later on for something else.
How does everyone else handle this? Or can you point me to a web-resource that explains the best way to handle this?
Thanks for putting up with newbie questions!
Hello and welcome!
Most games don’t really start paused (meaning game suspended with the pico8 pause menu open), rather they have a title screen and require a user action to transition into main game screen.
The concept you need is: game states!
Have a global variable to record if the game is in title or main (could be a boolean true/false or a string used with == comparisons). In _update, if we are in title AND button is pressed, then change state to be main. If we are in main AND button is pressed, then something else happens.
Does that make sense?
(There are more advanced ways for this to handle more complicated states and transitions, but it’s best to start simple!)
So here's how I handle pausing. I have a bool I usually call "paused", which in your case would be set to "true" at the start. Then, inside my update function, I'll put all the things I don't want to update inside a conditional like:
paused = true function _update() if not paused then --put everything that I want to not update while paused end --outside that conditional, I put everything that should update even while paused like UI, music, etc. --then, to flip paused/unpaused... if (btnp(X)) paused = not paused end
You can of course put whatever button you want to flip the boolean.
Hope this helps.
Merwok -- Thank you so much for the explanation. I think I understand that. Actually, I think I have been doing a hacked version of that, but I see notes I should be E to do a cleaner jobs of coding it. Thanks!
UnitVector -- Thanks! Sorry I didn't get back sooner, I thought I had subscribed to replies, but I didn't, so I didn't know you had back. Sorry! I ended up doing something like you suggested (I got the idea from a RayLib tutorial). But I had trouble with the Button being read a ton of times a second flipping paused from true to false like a dozen times in one press! I ended up using X for pause and Z for play, but I'm still not sure of my error... any thoughts?
Note that btnp will repeat after some time if the button is kept pressed; this can be configured: https://www.lexaloffle.com/dl/docs/pico-8_manual.html#BTNP
[Please log in to post a comment]