Priority4 - Priority based state machine

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:

  1. 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)
  1. 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)
  1. 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
  1. 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)
6 Likes

UPDATE:

added server—>client replication

UPDATE:

  • Statemachine wont be replicated to player if the player never used it

This update should fix some errors and lower the recv

This is very confusing… I would never remember that setting one value could actually set two different ones depending on the value type. I’d rather just set those two properties directly.

I can’t say much else since I don’t know what a state machine is.

2 Likes

UPDATE:

  • Major bug fixes
  • Better error handling
  • Better network performance
  • Integrated BridgeNet2 into the module