Skip to content
Mors edited this page Mar 31, 2022 · 3 revisions

wFSM API Reference

Constructors

State()

A state that can be added to a StateMachine.

 

StateMachine()

A finite state machine.

 

Static Methods for State

on_enter()

The event that gets called when StateMachine enters the current state.

 

on_leave()

The event that gets called when StateMachine leaves the current state.

 

on_update()

The event that gets called when the "update" method of the StateMachine is called.

 

Static Methods for StateMachine

add(index, state)

Adds a state to the finite state machine.

Param Type Description
index mixed The unique index variable used to keep track of the state. Using enums is recommended, but you can also use strings if you really want to.
state struct The state to be added.

 

remove(index)

Removes a state from the finite state machine.

Param Type Description
index mixed Index of the state that's going to be removed.

 

change(index)

Changes the current state of StateMachine to the provided index.

Param Type Description
index mixed Index of the state that's going to be set as the new one.

 

next()

Changes the current state of the current StateMachine to the next one.

 

reset()

Works similarly to "change(index)" but it will "change" to the state that is already running, essentially resetting the current state.

 

get() ⇒ real

Returns the current state index of the current StateMachine.

Returns: The current state index of the current StateMachine.

 

count() ⇒ real

Returns the number of states within the current StateMachine.

Returns: The number of states within the current StateMachine.

 

timer() ⇒ real

Returns the number of frames that have passed since the State has been initialized.

Returns: The number of frames that have passed since the State has been initialized.

 

clear()

Clears all the states from the current StateMachine.

 

destroy()

Destroys the current StateMachine to free the memory.

 

update()

Executes the "update" event of the current State.

 

run_event(event_name)

Executes a specific event of the current State.

Param Type Description
event_name string Name of the event to execute.