Hi, i'm new to pico 8 programming so i was trying to redo the pong game from the pico-zine 1! I understood almost all the code (minus the collision stuff) and i was trying to make the game restart when pressing a specific button (for example X). I tried "while btnp(5) == 1 do" but it isn't working as inteded.. What i'm missing is a way to hang the game until the button is pressed and how to restart the game completely... This is the cart i'm working at atm (i commented the broken function)
Thanks!



You need some form of state machine, eg:
- variable(s) to hold state
- action to transition from one state to another
Pseudo code with a single ‘game_over’ state:
local game_over=false function _update() if ... player lost ... then game_over=true ... other state change as need like switch current screen to welcome screen ... end if game_over==true and btnp(5) then game_over=false ... reset player lives, score, enable game screen... end end |



Thanks freds72! I had to make some IFs in the _draw() function too, is that the "correct" way of doing so? Because if i tried to RECTFILL or PRINT in the _update function it didn't show anything (i'm assuming because it's refreshed too fast?).. Besides, if i wanted to make a simple menu, should i write some IFs in the _draw() function? Like
menu = 1 if menu then --PRINT THE MENU end if menu == 0 then --start the game end |



You got it. Key aspect is to change state only in update and use state in draw (e.g. ‘if’ in draw is normal!)



Thanks a lot! Can you actually recommend me some nice PICO tutorials? I read the PICO-zines and it feels like it goes from "hello world" to something very difficult rather quickly... Thanks a lot again!



Hu...I got 20+ years of programming under the belt, so no real need of tutorials :]
Seriously, get back to the basics, e.g. generic programming tutorial. Get a firm grasp of data structures, control flow... and experiment "theory" with some basic pico-8 demo.



this thread is super old but I had this exact question, theres a function called "extcmd" which can reset the cart
source: https://nerdyteachers.com/PICO-8/Guide/EXTCMD
[Please log in to post a comment]