Hey guys, I’ve been working on my player’s script, and was wondering if using one integer to handle actions rather than a Boolean for every action would work better in terms of performance, or it would it be negligent?
I ask now because I don’t want to finish the whole thing only to find out one way is better than the other.
Integers are far better, since you only test the movement state in a switch rather than checking each boolean and trying to determine which to check for first.
It also translates to player movement, as it makes it simple to accept only the input you need for that state, instead of having a bunch of conditional statements for all the edge cases. If you’re in the falling state, only check for the parachute button and make that transition to the floating state, for example. The logic will be nicely grouped with each state, and the code gets easier to read. Out of sight, out of mind is very true when the code stretches past one visible screenful of text
also if your usecase dosnt need a full state machine you can use a Enum works like a int, but is named so things are more readable. they work really well if you use a enum in a switch statemeant