Love2D: A state switcher class (Lua)
Simple state switcher class for Love2D / Lua that uses one file per state. It completely covers Love 2D state management for the game developers. Licensed under CC-BY 4.0 / Creative Commons Attribution International 4.0.
Download:
stateswitcher.zip (2,7 Kb; for Love2D / Lua)
Code example:
state=require("stateswitcher")
state.switch("credits") -- switching to credits.lua
Code example with passing a value:
state=require("stateswitcher")
state.switch("credits;2;hello") -- passing 2 as the first value, "hello" as the second value
Code example to retrieve the values passed after switch:
state=require("stateswitcher")
step=passvar[1] -- gets the first value = 2
greeting=passvar[2] -- = "hello"
state.clear() -- clearing the values passed, so no zombie values hang around
Other advantages:
- edit your code & save to see changes immediately after state switch (without leaving your program)
- reuse the functions from the previous states (to keep same behaviour) or redeclare the functions (to change behaviour)