Skip to main content
gamedev.net
🔒 Locked

Strange problem

Started by Peon Jan 22, 2001 at 11:34 PM 5 replies 400+ views
Original Post
Peon
Peon
This problem has been confusing me forever. This is how it goes everytime: I have a global (game_state or whatever) that keeps track of the state of the game (ie: menu, running, etc...) I then do a check in GameMain() to choose which function to run. Anywho... Look at this code below:
  while(true)
	{
    // test if there is a message in queue, if so get it

	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	   { 
	   // test if this is a quit

       if (msg.message == WM_QUIT)
           break;
	
	   // translate any accelerator keys

	   TranslateMessage(&msg);

	   // send the message to the window proc

	   DispatchMessage(&msg);
	   } // end if


	   //check app state

	   if (AppState == 0)
	   Setup();
	   else
	   if (AppState == 1)
		   Game_Main();
	   	          
	} // end while


// closedown game here

Game_Shutdown();

// return to Windows like this

return(msg.wParam);

} // end WinMain  
(I took a lot of it from LaMothe, if it looks familiar...) Ok, this is the problem. When the game starts, it runs Seup() fine. The setup simply simply allows the user to select a sprite size (I''m actually writing a simple sprite editor to help me do sprites) by clicking on the size the want. I got that to work. Upon clicking, the AppState becomes 1 (active) and so GameMain should execute. Only, it doesn''t. I am 100% GameMain() never executes. Shutdown(), however, does run. I did a check to make sure AppState did indeed equal 1 and it does. What''s the problem here? I''m kinda a newbie -- go easy Thanks in advance, Peon
Peon
BloatWare
BloatWare
Try putting curly braces around the last if statement, like so,

  
if (AppState == 0)
Setup();
else
{
if (AppState == 1)
Game_Main();
}


Edited by - BloatWare on January 23, 2001 7:42:53 AM
Eraserhead
Eraserhead
quote:
Original post by BloatWare

Try putting curly braces around the last if statement, like so,

if (AppState == 0)
Setup();
else
{
if (AppState == 1)
Game_Main();
}


That doesn''t matter. else if statements are perfectly valid. The code should work correctly as Peon wrote it(at least that part). Try stepping into the code with a debugger.

PS: You might also consider using constants for the AppState variable to make the code more readable, like this:
      
#define AS_SETUP 0

#define AS_GAMEMAIN 1


or even better:
    
const int AS_SETUP=1;
const int AS_GAMEMAIN=1;
Quark
Quark
I am assuming that after setup is run you change app_state to 1, then this is because your second if statement is being skipped.

Try removing the else statement as below.

if (AppState == 0)
Setup();
if (AppState == 1)
Game_Main();

Hope this helps
If knowledge is power and power corrupt, does knowledge corrupt? — James Moore.Never understimate stupid people in large groups.—Unknown.
Peon
Peon
Thanks for the help all I reviewed my code and discovered the problem was not with what I showed you but with a function I wrote to check if a mouse click was inside a given rectangle (using DirectInput) I''m still baffled by the problem but I know how to fix it, hehe. I just did a test input, sending the function numbers instead of a RECT structure and everythign worked. Interesting

So refresh my memory please, how do I send a RECT structure to a function? Or is there a cleaner way to detect mouse clicks in a box? (I''m a DirectInput newbie, too )

Thanks,
Peon
Peon

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.