Log In  

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


if not keypressed('esc') ...etc.

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?


P#57246 2018-09-29 03:16 ( Edited 2018-10-01 15:28)

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)
function _update()
 if game_mode==‘waiting’ then
  — update game variables as needed
  — transition out?
  if any_btn() then
 elseif game_mode==‘playing’ then
  — update game
  — transition out?
  if plyr.health==0 then
 elseif ...
function _draw()
 if game_mode==‘waiting’ then
  print(‘press any button’, 64,64,7)
 elseif game_mode==‘playing’ then
   print(‘insert game here :)’,64,64,8)

note: this can be vastly improved by having game states creating objects with their own update/draw functions and other niceties (like timed transitions)

P#57252 2018-09-29 07:02 ( Edited 2018-09-29 11:04)
:: dw817

Errm ... If you just want a simple, "Hit a key to continue."

print"Hit a key to continue."
until btnp(4)

Hit key (Z) on the IBM-pc to ... continue. :)

P#57258 2018-09-29 11:30 ( Edited 2018-09-29 15:30)

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.

P#57327 2018-10-01 01:40 ( Edited 2018-10-01 05:40)
:: Davbo

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
 elseif gamestate=="playing" then
  -- etc
P#57330 2018-10-01 05:50 ( Edited 2018-10-01 09:50)
:: dw817

Oh ? I didn't know that. BTNP() no arguments covers all buttons. Good to know !

P#57334 2018-10-01 11:28 ( Edited 2018-10-01 15:28)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-03-30 09:43 | 0.012s | 4194k | Q:23