State Machine Hell
Okay so, I came across a nice little fix for my menu and start game problem in my coding. The problem is that I got errors coming from every orifice mostly the top half. This is the template I had: http://gamedevelopment.tutsplus.com/articles/how-to-build-a-jrpg-a-primer-for-game-developers--gamedev-6676
And Unity was loving it for the first few bits. Any tips would help and other than the StateMachine I got it all word for word.
class StateMachine {
Map<String, IState> mStates = new Map<String, IState>();
IState mCurrentState = EmptyState;
StateMachine gGameMode = new StateMachine();
gGameMode.Add("mainmenu", new MainMenuState(gGameMode));
gGameMode.Add("openingscrean", new OpeningScreanState(gGameMode));
gGameMode.Add("localmap", new LocalMap(gGameMode));
gGameMode.Change("openingscrean");
public void Update(float elapsedTime) {
mCurrentState.Update(elapsedTime);
}
public void Update() {
float elapsedTime = GetElapsedFrameTime();
gGameMode.Update(elapsedTime);
gGameMode.Render();
}
public void Render() {
mCurrentState.Render();
}
public void Change(String stateName) {
mCurrentState.OnExit();
mCurrentState = mStates[stateName];
mCurrentState.OnEnter();
}
public void Add(String name, IState state) {
mStates[name] = state;
}
}
No problem, I also running 5.3.5. First and foremost "$$anonymous$$ap String, IState" is co$$anonymous$$g in as not found.
This little guy and his family is just said to be invalid:
gGame$$anonymous$$ode.Add("mainmenu", new $$anonymous$$ain$$anonymous$$enuState(gGame$$anonymous$$ode));
Should I make him a $$anonymous$$ethod?
Just a note - you clicked on the big reply button, which means Answer not Reply! Not very intuitive but there you go. When replying you'll find a tiny Reply to the right of the name of the poster, or click Add Comment.
I've converted it to a comment this time :)
Answer by Mmmpies · Jun 01, 2016 at 02:45 PM
As it turns out I could have just looked at that tutorial. Look at the top..
So that code you typed in is "Psudo JS" otherwise known as BS!
I'd find a different tutorial to go off if I were you and if possible try one that's C# unless you already know a fair bit JS. C# is faster in unity and if you're learning a new language anyway C# will be better as the unity tutorials are in that.
EDIT - got a bit of time to look and THIS looks pretty good if you're trying a 2D RPG style game.
Answer by ericbegue · Jun 02, 2016 at 07:28 AM
Hi,
Finite State Machine (FSM) can quickly become a hell to manage as the number of states is growing. Because the number of transitions grows quadratically and any modification to the state machine requires to fiddle with the transitions, which is tedious and error prone.
If you are looking for an alternative to FSM, have a look at Behaviour Tree, which is far more flexible and easier to manage.
I'm the author of Panda BT (www.pandabehaviour.com), it's a script based behaviour tree engine.
If you have a question about using this tool, you're welcome on this thread.
Your answer
Follow this Question
Related Questions
Can't Open Exit Time Settings 0 Answers
Can someone help me? No matter what I change it still says "Parsing error". 2 Answers
NullReferenceExpection: Object reference not set to an instance of an object error. 1 Answer
Android Cardboard SDK published to WebGL 0 Answers
Can someone help me fix this script up? 2 Answers