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!
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.
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.
[Please log in to post a comment]