help with SuperSmashBro's type game

I need information to be passed from CharSelect::Logic() and MapSelect::Logic() to class Game.

My state machine looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
while( currentState->nextState != STATE_EXIT)
{
	currentState->HandleEvents();
	currentState->Logic();
	currentState->Render();
		//if needed, change state
	switch( currentState->nextState )
	{
	case STATE_MENU:
		delete currentState;
		currentState = new Menu( &GameEnvironment );
		break;
	case STATE_CHARSELECT:
		delete currentState;
		currentState = new CharSelect( CharactersChosen, GameEnvironment );		
        case STATE_MAPSELECT:
		delete currentState;
		currentState = new MapSelect( MapChosen, &GameEnvironment );
	case STATE_GAME:
		delete currentState;
		currentState = new Game( MapChosen, CharactersChosen, &GameEnvironment );
		break;
	case STATE_EXIT:
		break;
	}
}



CharactersChosen and MapChosen are vectors that are being passed by reference. The idea was that i could send them to their appropriate States, modify them, then send them to the Game state.

BUT they are only sent to the constructors of CharSelect and MapSelect, and i need to use them in CharSelect::Logic() and MapSelect::Logic().
Last edited on
As for me, I haven't understood anything.
I have no idea what you're saying and you're not even asking any questions, but two cases in your switch have no break statement, so they'll fall right through to STATE_GAME.
that isnt my problem helios( although thank you for letting me know ).


Let me give you an example of what i want to happen.

In SuperSmashBrothersBrawl there is a screen where you can pick to play multiplayer. Lets say that is STATE_MENU. You click to play and a screen comes up where you can choose your characters, or STATE_CHARSELECT. Then another screen comes to choose the stage you would like to play on, or STATE_MAPSELECT. After all that, you can they play the game with the selected characters on the selected map.


My problem is that the way my state machine is set up, i cant figure out a way to do that^^. So im asking you to help me fix me state machine so that it would be possible to do the above.
bump
closed account (zwA4jE8b)
just go in order of events

state = STATE_MENU;
...choose option
if(choice == multiplayer)
state = STATE_CHARSELECT;
else
....

again like helios said, any time you enter STATE_CHARSELECT you will end up in STATE_GAME
Last edited on
Yeah but that wont work because each state is deleted when the next one is called, so the information is lost. I need to use information STATE_CHARSELECT and STATE_MAPSELECT to play the game. I remember reading about a statemachine with vectors but i dont really remember how to do it.

But basically, you pop on a state to the vector when you want that state to run ( it always runs the last state in the vector ) and if you need states to get information from another state you just stack them on top. Like a STATE_GAME would need information from STATE_SETTINGS, so they would be stacked. but STATE_GAME doesnt need information from STATE_MENU so STATE_MENU is deleted when its not being used.

The problem is i dont know how to implement it
Last edited on
Okay i figured out what im looking for is called a Stack Based State Machine.

Im going to go redo my whole statemachine now lol
Topic archived. No new replies allowed.