Hello Robloxians and Developers, Pretty funny eh?
Anyway… I have made yet another helpful module for devs, To save you about hmmm… 120 lines? and 1-2 hours of your time making an state machine.
Yes you saw it right, State Machine.
I have made an generalized state machine module that allows you to have StateMachine for anything you want, With exit
, update
and enter
functions.
What is a State Machine? Source
A state machine is a behavior model. It consists of a finite number of states and is therefore also called finite-state machine (FSM) (Not all state machines are limited to finite amount of states). Based on the current state and a given input the machine performs state transitions and produces outputs. There are basic types like Mealy and Moore machines and more complex types like Harel and UML statecharts.
Links
Generalized State Machine: create.roblox.com/store/asset/116036508889370
Me (Roblox): ItzMrRatsP - Roblox
I am always looking for tips and trying to improve, So please if you think i can do something better then reply to this and let me know
5 Likes
Forgot to add that in there, But there i do have a wally package for it too.
genericstatemachine = "itzmrratsp/genericstatemachine@0.1.1"
I think it’s important to note that not all state machines have finite states, This line seems to incorrectly state this:
I can provide some examples of ISMs, but they are largely unused in game development. BIggest examples would probably be integer counters, turing machines, and Neal.fun’s InfiniteCraft.
3 Likes
A good example of a StateMachine within Roblox (built in) are the Humanoid States, alongside with the EvaluateStateMachine property.
1 Like
I didn’t write this, I put the source up there. But i will add that in.
Thanks!
1 Like
Update: I removed the way of updating stuff, I made it more of other scripts job to do, Removed some mistakes i made around the script for example unnecessary check on exit state.
Wally: StateMachine = “itzmrratsp/genericstatemachine@0.1.33”
Github: GitHub - ItzMrRatsP/StateMachine: Generalized StateMachine Package for wally
State Machine Enhancements
The state machine has been upgraded with several key improvements to enhance usability and robustness:
- Case-Insensitive State Handling
All methods that accept a stateId
parameter now support case-insensitive matching. This ensures consistent behavior regardless of input casing. For example:
state:add("TEST", state_functions)
state:remove('teSt") -- Still removes the "TEST"
This flexibility reduces input errors and improves developer experience.
- Improved Consistency & Reliability
The internal state resolution has been standardized to normalize state IDs, ensuring predictable behavior across all operations.
These updates maintain backward compatibility while making the state machine more intuitive and resilient.
Published updates to the Roblox version of StateMachine, You need to re-import the module