Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@gandalfwisdom/statebuddy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
StateBuddy
A simple state machine class in roblox.
Dependencies
This resource is dependant on the Nevermore framework. It will not work without it.
Features
StateBuddy allows you to easily manage, create, and remove states with features such as:
- Set Enter, Started, and Completed functions respectively.
- Set a lifetime for your states, giving them a limited run-time if needed.
- Set any function parameters necesary for your needs. (Each state can have it's own custom params)
- All StateBuddies can be named and are logged into a centralized table so you can index the current state of any StateBuddy object currently active by just the name.
- Full --!strict mode support.
Usage
Initialize your StateBuddy object:
local state_buddy = StateBuddy.new("BuddyName");
Add your states:
local function set_states()
state_buddy:AddState(
"Idle", -- Name
0, -- Duration
function(...) -- Enter
return true;
end,
function(...) -- Started
end,
function(...) -- Completed
end,
);
-- ... Other states added below here.
end;
Change your states at will with :ChangeState():
state_buddy:ChangeState("Reloading");
If your states will have limited duration, connect the :Update() method in the StateBuddy object to a loop:
RunService.Heartbeat:Connect(function(delta_time: number)
state_buddy:Update();
end);
Installation
StateBuddy supports Nevermore's npm package installation method.
Simply type npm install @gandalfwisdom/statebuddy
in your CLI on your project to install.
Snippets
Speed up your workflow by pasting some useful snippets in your VSCode snippets folder.
Easily add new states with this :AddState() snippet:
"StateBuddy State": {
"prefix": "state",
"body": [
"${1:Foo}:AddState(",
"\t\"${2:StateName}\",",
"\t0,",
"\tfunction() -- Enter",
"\t\treturn true;",
"\tend,",
"\tfunction() -- Started",
"\tend,",
"\tfunction() -- Completed",
"\tend",
");"
]
},