-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from prooheckcp/Version117
RobloxStateMachine - V.1.1.7
- Loading branch information
Showing
23 changed files
with
500 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
:root { | ||
--primary-color: #86C232; | ||
--secondary-color: #61892F; | ||
--background-color: #222629; | ||
} | ||
*/ | ||
|
||
:root { | ||
--primary-color: #53900F; | ||
--secondary-color: #1F6521; | ||
--background-color: rgba(34,38,41,1); | ||
} | ||
|
||
html[data-theme='dark']{ | ||
--ifm-background-color: var(--background-color); | ||
--ifm-color-primary: var(--primary-color); | ||
--ifm-color-primary-dark: var(--primary-color); | ||
--ifm-color-primary-darker: var(--primary-color); | ||
--ifm-color-primary-darkest: var(--primary-color); | ||
--ifm-color-primary-light: var(--primary-color); | ||
--ifm-color-primary-lighter: var(--primary-color); | ||
--ifm-color-primary-lightest: var(--primary-color); | ||
--ifm-background-color: var(--background-color); | ||
--ifm-code-font-size: 95%; | ||
--ifm-navbar-background-color: var(--secondary-color); | ||
--ifm-footer-background-color: var(--secondary-color); | ||
--ifm-background-color: var(--background-color); | ||
--ifm-footer-background-color: var(--secondary-color); | ||
--ifm-footer-color: var(--ifm-footer-link-color); | ||
--ifm-footer-link-color: var(--ifm-color-secondary); | ||
--ifm-footer-title-color: var(--ifm-color-white); | ||
} | ||
|
||
.footer--dark { | ||
--ifm-footer-background-color: var(--secondary-color) !important; | ||
--ifm-footer-color: var(--ifm-footer-link-color) !important; | ||
--ifm-footer-link-color: var(--ifm-color-secondary) !important; | ||
--ifm-footer-title-color: var(--ifm-color-white) !important; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
sidebar_position: 4 | ||
sidebar_label: "🔍 Access internals" | ||
--- | ||
|
||
# 🔍 Access internals | ||
|
||
While inside a state or transition you can actually access to a lot of information about our state machine! | ||
To do this all you have to do is call **self** from within any of the virtual methods. | ||
|
||
Here's an example of what you can access from within the state | ||
```lua | ||
-- Blue.Lua | ||
local GoToRed = require(script.Parent.Parent.Transitions.GoToRed) | ||
local ChangeColorState = require(script.Parent.ChangeColorState) | ||
|
||
local Blue = ChangeColorState:Extend("Blue") | ||
Blue.Transitions = {GoToRed} | ||
|
||
function Blue:OnEnter() | ||
print(self.Data) -- Get state machine data | ||
self:ChangeState("Red") -- Changes the current state to Red | ||
self:GetState() -- "Blue" | ||
self:GetPreviousState() -- Gets the previous state this state machine was in before Blue | ||
self:ChangeData() -- Changes data from the state machine | ||
end | ||
|
||
|
||
return Blue | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
sidebar_position: 2 | ||
sidebar_label: "🚀 Extend States/Transitions" | ||
--- | ||
|
||
# 🚀 Extend States/Transitions | ||
|
||
We can extend classes that share behavior with one another. In fact we do this in one of our examples! | ||
|
||
Let's see how this works in practice. First you start by creating a Parent State. This is the state from which other states will be created. | ||
|
||
|
||
```lua | ||
--ChangeColorState.lua | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
|
||
local RobloxStateMachine = require(ReplicatedStorage.RobloxStateMachine) | ||
|
||
local State = RobloxStateMachine.State | ||
|
||
local ChangeColorState = State "ChangeColorState" | ||
|
||
function ChangeColorState:OnInit() | ||
self.Color = Color3.fromRGB(255, 255, 255) | ||
end | ||
|
||
function ChangeColorState:OnEnter(data) | ||
data.part.Color = self.Color | ||
end | ||
|
||
function ChangeColorState:OnDestroy() | ||
print("Destroy Instance") | ||
end | ||
|
||
return ChangeColorState | ||
``` | ||
|
||
Now that we have our parent class that defines are behavior on which we will be changing the part color to what has been defined in the | ||
init function we can now make new states! Let's create a blue and red state | ||
|
||
```lua | ||
--Red.lua | ||
local GoToBlue = require(script.Parent.Parent.Transitions.GoToBlue) | ||
local ChangeColorState = require(script.Parent.ChangeColorState) | ||
|
||
local Red = ChangeColorState:Extend("Red") | ||
Red.Transitions = {GoToBlue} | ||
|
||
function Red:OnInit() | ||
self.Color = Color3.fromRGB(255, 0, 0) | ||
end | ||
|
||
return Red | ||
``` | ||
|
||
```lua | ||
--Blue.lua | ||
local GoToRed = require(script.Parent.Parent.Transitions.GoToRed) | ||
local ChangeColorState = require(script.Parent.ChangeColorState) | ||
|
||
local Blue = ChangeColorState:Extend("Blue") | ||
Blue.Transitions = {GoToRed} | ||
|
||
function Blue:OnInit() | ||
self.Color = Color3.fromRGB(0, 0, 255) | ||
end | ||
|
||
return Blue | ||
``` | ||
|
||
By doing this we didn't have to define the changing color behavior on both blue and red! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
sidebar_position: 3 | ||
sidebar_label: "🛑 Stop State Transition" | ||
--- | ||
|
||
# 🛑 Stop State Transition | ||
|
||
There's specific situations where we might want to "stuck" a state machine on a specific state. | ||
For this purpose there's a virtual method specifically for this! | ||
|
||
```lua | ||
--Blue.lua | ||
local GoToRed = require(script.Parent.Parent.Transitions.GoToRed) | ||
local ChangeColorState = require(script.Parent.ChangeColorState) | ||
|
||
local Blue = ChangeColorState:Extend("Blue") | ||
Blue.Transitions = {GoToRed} | ||
|
||
function Blue:OnInit() | ||
self.Color = Color3.fromRGB(0, 0, 255) | ||
end | ||
|
||
function Blue:CanChangeState(newState: string) | ||
return newState == "Red" | ||
end | ||
|
||
return Blue | ||
``` | ||
|
||
By doing this we ensure that the state blue can only be changed to the new state **IF** the new state is equal to "Red". | ||
|
||
We could also block the player into this state entirely by simply returning false. | ||
|
||
```lua | ||
function Blue:CanChangeState(newState: string) | ||
return false | ||
end | ||
``` | ||
|
||
This can be specially useful to per e.g to stuck an NPC into the dead state since we don't want him to magically revive! | ||
|
||
In case you're wondering what would happen if didn't declare this method. :CanChangeState returns **true** by default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[docusaurus] | ||
onBrokenLinks = "throw" | ||
onBrokenMarkdownLinks = "warn" | ||
favicon = "RobloxStateMachineIcon.png" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.