Comments (6)
- A common solution to that is macro-ing the state names. It works as well as an enum in this case.
- I really dislike this sort of comparison/ arithmetic operations with enums. This makes the code harder to follow and prone to errors as you expand. I highly disagree on this being more maintainable than doing:
states_to_check = ["idle", "walk", "skid_to_stop"];
if (array_find_index(states_to_check, fsm.get_current_state()) != -1) {
// Do stuff
}
OR, you can make use of SnowState's inheritance! (if possible)
fsm.add("state_to_check");
fsm.add_child("state_to_check", "idle", { /* Behavior */ });
fsm.add_child("state_to_check", "walk", { /* Behavior */ });
fsm.add_child("state_to_check", "skid_to_stop", { /* Behavior */ });
if (fsm.state_is("state_to_check")) {
// Do stuff
}
from snowstate.
hey friend are you open to accepting PRs on this one?
from snowstate.
I'm still deciding on this feature - and I'm leaned towards not allowing anything other than strings.
What benefits do you think enums bring? (You can also stringify enum entries and pass them)
from snowstate.
Hi!
So the main use cases I've run into are:
- Just basic error prevention by taking advantage of the code completion in GMS2. Easier to make sure everyone is using the right state names if they're conveniently in an enum. This can be addressed as you say by stringifying them though!
- The second is doing comparisons and operations on the integer the Enum points to:
(if fsm.get_current_state() <= E_STATES.ACCEPT_INPUTS)
Is much easier and more maintainable than having to chain comparisons:
(if fsm.state_is("walk") || fsm.state_is(""idle") || fsm.state_is("skid_to_stop")
You can also potentially add or substract to the enum for varying degrees of intensity or for alternate forms etc.
from snowstate.
We discussed on Discord, thanks :D Posting this in case someone else is interested in the question:
I'm convinced that the advantages of readability are worth losing out on being able to do math on the enum integer, and input validation can be handled other ways as you said. The inheritance paradigm here is very strong, missed that.
There's a second argument about under the hood performance using enums and arrays rather than structs, but that would require new plumbing and is outside the scope of this original feature request.
from snowstate.
The other solution requires a rewrite (of most of SnowState) and I am considering it.
from snowstate.
Related Issues (20)
- state_exists HOT 1
- add_child doesn't "override" HOT 1
- Can't check wildcard transition using transition_exists() HOT 1
- Passing arguments to triggers HOT 1
- Assignment of an empty value - When running using YYC HOT 1
- Ability to pause timer HOT 3
- Leave event
- Beta Variable not set before reading error HOT 1
- Can not use same name for a SnowState instance event and the owner's instance variable HOT 1
- Allow an option to not trigger enter/leave events using the change() method HOT 1
- Third Level Inherited States Execute Their Inherited Parent's Events Twice
- When running the game after downloading get move_and_collide is a read-only function HOT 6
- Add method for getting the initial state
- Changing another object's state in a leave event still cause the object to run the now-previous state's step event HOT 3
- inherit() does not support parameters HOT 2
- Internal variables for states HOT 1
- HTML5 support is broken HOT 3
- Object: oPlayerT Event: User Event 15 at line 53 : "move_and_collide" is read-only function in latest GameMaker monthly version HOT 1
- Changing state during multiplayer causes a crash HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snowstate.