Log In  


Has anyone got a suggestion for a sensible way of implementing a menu/selection system in Pico-8? I'm putting together a minigame collection, and trying to keep the code readable when everything has to share the same space (e.g. the init/update/draw loops) is proving a challenge!

Thanks y'all!

P#13706 2015-09-05 04:17 ( Edited 2015-09-06 00:59)

A statemachine and subfunctions.
Use one variable to set what state you are, and replace _update and _draw with just calls to UpdateGame, UpdateMenu, UpdatePause etc type functions.

How you would do it in c++ or something would be a switch/case, but iirc that isn't in LUA, so you need to do it with if/elseif.

P#13713 2015-09-05 08:46 ( Edited 2015-09-05 12:49)

Give each game its own init, update, draw. Make those methods on a table per game. Assign the current game's table object to a global variable called mode that is a reference to the current game . Call mode:init() in the global _init(), thereby calling the current game's init(), and so on.

P#13714 2015-09-05 08:53 ( Edited 2015-09-05 12:53)

Thanks! That's all really helpful - now I have a direction to work in!

P#13729 2015-09-05 16:38 ( Edited 2015-09-05 20:38)

Thanks for the (indirect) suggestion!

Because of you guys, I've added a Title/menu screen to my WIP (it'll come on the BBS soon, don't worry)!

P#13731 2015-09-05 20:59 ( Edited 2015-09-06 00:59)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-18 23:47:38 | 0.007s | Q:16