Hello all. I'm having a bit of a brain-fart here as I can't work out how to do a 'Press any key to continue' routine!
In my old ZXSpectrum or BlitzBasic days it used to be along the lines of...
10 if inkey$<>"" then goto 10
or
while
if not keypressed('esc') ...etc.
wend
I know we have limited BTNs but I can't figure out how to do it neatly. I can do it using a load of GOTOs and separate functions, but it's unnecessarily complicated and there must be a simpler way!
Any help?
Noob.
Back in the days (as you mentionned) we all missed a good state management!
Overall how to:
- have a global variable that captures game mode (title, game, waiting...)
- according to the game mode, define how to transition to the next state (can be buttons, player health, timer...)
local game_mode=‘waiting’ function any_btn() return btn(4) or btn(5) end function _update() if game_mode==‘waiting’ then — update game variables as needed ... — transition out? if any_btn() then game_mode=‘playing’ end elseif game_mode==‘playing’ then — update game — transition out? if plyr.health==0 then game_mode==‘waiting’ end elseif ... ... end end function _draw() cls() if game_mode==‘waiting’ then print(‘press any button’, 64,64,7) elseif game_mode==‘playing’ then print(‘insert game here :)’,64,64,8) end end |
note: this can be vastly improved by having game states creating objects with their own update/draw functions and other niceties (like timed transitions)
Errm ... If you just want a simple, "Hit a key to continue."
print"Hit a key to continue." repeat flip() until btnp(4) |
Hit key (Z) on the IBM-pc to ... continue. :)
If 'any key' includes direction keys, X and O, then you can just check if btn() returns a value higher than 0.
-- warning: untested, writing this on a train if (btn()>0) state="continue" |
The pico8 wiki states:
When btn() is called without arguments, it returns a bitfield of the button states for players 0 and 1.
Doczi is correct, I did this for my wee game throw punch
if gamestate=="mainmenu" then --any button starts the game if btnp() != 0 then gamestate="playing" end elseif gamestate=="playing" then -- etc |
Oh ? I didn't know that. BTNP() no arguments covers all buttons. Good to know !
[Please log in to post a comment]