I'm trying to make my game pause if the user presses the 'P' button, and then unpause again with the P button. The pausing works when it's only pausing:

game_state = PAUSED;

I've currently tried the following with pausing and unpausing - none have worked:

switch(game_state)
		{
			case RUNNING:
			{
				game_state = PAUSED;
				break;
			}
			case PAUSED:
			{
				game_state = RUNNING;
				break;
			}
			default:
			{
				game_state = PAUSED;
				break;
			}
		}
if(game_state == PAUSED)
			game_state = RUNNING;
		else if(game_state == RUNNING)
			game_state = PAUSED;
if(game_state == RUNNING)
			game_state = 500;
		else if(game_state == PAUSED)
			game_state = RUNNING;
		if(game_state == 500)
			game_state = PAUSED;

I've also tried other things similar to the ones above. Does anyone know a way for this to work?

The switch should work just fine. Make sure that your game loop is checking it appropriately and that you haven't defined the RUNNING and PAUSED constants to be the same value (by copy-paste oversight or whatever).

The switch should work just fine. Make sure that your game loop is checking it appropriately and that you haven't defined the RUNNING and PAUSED constants to be the same value (by copy-paste oversight or whatever).

All of that's fine. If the switch statement is good, then I think the problem is with keystrokes. I'm not checking to see if P was just pressed, but just if it's down. I had the same problem with mouse buttons. I would have to have prevkeystate[] as an array or something to check if the key was just pressed.

I encountered such a problem when one of our programmers, by pressing keys ESC (pause the game) disable the rendering. The engine was designed so that events are not intercepted when rendering was stopped (and this is quite logical).
Try to arrange a pause in some other way. For example:
at the time of rendering a new frame, define the state of the game "freezes"

Very simple, 1 line solution.
Make a boolean variable called pause:

pause = !pause;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.