Listen:
If you want to have full control over state machines: use Priority3.
Priority4 is new and doesn’t have a lot of features but I will add more features soon.
Why use Priority4 instead of Priority3:
I’ve used as much metamethods as I could to make this module intuitive and convenient/easy to use sooo if you want to keep your scripts as clean as possible then you should probably use Priority4.
Download:
How to use:
- use the GetMachine function of the module to create/get a StateMachine for your object/key
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Priority4 = require(ReplicatedStorage:WaitForChild("Priority4"))
local machine = Priority4.GetMachine(workspace)
- creating/changing States
-- module will automatically create the state if it doesnt exist
machine.Walking = true -- enables state
machine.Walking = false -- disables state
machine.Walking = 1 -- sets priority to 1 (default is 0)
machine.Walking.Changed:Connect(function(enabled, active)
-- fires everytime the state is updated
end)
- I’m going to add another state with a higher priority to show you how the module will react to it
machine.Running = true -- enables state
machine.Running = 2 -- sets Priority to 2
-- now machine.Walking.Active will turn to false and machine.Running.Active will turn true because Running is enabled and has a higher priority than Walking
- printing/getting states
-- first ball indicates .Enabled property
-- second ball indicates .Active property
print(machine) -- prints: Running:🟢🟢 Walking:🟢⚫
print(machine.Walking) -- prints: 🟢⚫
print(machine.Running) -- prints: 🟢🟢
-- print the properties manually if you want to see them as boolean
print(machine.Walking.Enabled) -- prints: true
print(machine.Walking.Active) -- prints: false
Full Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Priority4 = require(ReplicatedStorage:WaitForChild("Priority4"))
local machine = Priority4.GetMachine(workspace)
machine.Walking = true
machine.Walking = 1
machine.Running = true
machine.Running = 2
machine.Walking.Changed:Connect(function(enabled, active)
end)
machine.Running.Changed:Connect(function(enabled, active)
end)
print(machine)
print(machine.Walking)
print(machine.Running)