Difference between revisions of "Stateswitcher"

(Created page with "Simple state switcher class for Love2D / Lua that uses one file per state. Download: [http://www.ambience.sk/love2d-a-state-switcher-class-lua/ Stateswitcher class] == Code exa...")
 
m (Added: Other Languages)
 
(4 intermediate revisions by 3 users not shown)
Line 4: Line 4:
  
 
== Code example: ==
 
== Code example: ==
 +
<source lang="lua">
 
state=require("stateswitcher")
 
state=require("stateswitcher")
 
 
state.switch("credits") -- switching to credits.lua
 
state.switch("credits") -- switching to credits.lua
 +
</source>
  
 
== Code example with passing a value: ==
 
== Code example with passing a value: ==
 +
<source lang="lua">
 
state=require("stateswitcher")
 
state=require("stateswitcher")
 
 
state.switch("credits;2;hello") -- passing 2 as the first value, "hello" as the second value
 
state.switch("credits;2;hello") -- passing 2 as the first value, "hello" as the second value
 +
</source>
  
 
== Other advantages: ==
 
== Other advantages: ==
Line 20: Line 22:
 
- automate debugging - create a sequence of state switching with variables passed
 
- automate debugging - create a sequence of state switching with variables passed
  
 
+
{{#set:Name=Stateswitcher}}
{{#set:LOVE Version=0.9.1}}
+
{{#set:LOVE Version=Any}}
 
{{#set:Description=A state switcher library based on files (one file=one state).}}
 
{{#set:Description=A state switcher library based on files (one file=one state).}}
 +
{{#set:Keyword=State}}
 
[[Category:Libraries]]
 
[[Category:Libraries]]
 +
 +
== Other Languages ==
 +
{{i18n|Stateswitcher}}

Latest revision as of 15:31, 15 December 2019

Simple state switcher class for Love2D / Lua that uses one file per state.

Download: Stateswitcher class

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

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)

- automate debugging - create a sequence of state switching with variables passed

Other Languages