Archived

This topic is now archived and is closed to further replies.

Whats wrong with this loop?

This topic is 6167 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I was working away on my latest project on the main loop for it. I decided to use different states to represent the various states in the game (as you will see). Now I basically copied the loop from another program of mine, modified it and now it won''t work. Here''s the code:
  //the main game loop... Game::MainLoop() { //the main switch statement for the main game functions switch( Game_State ) { case Game_State_Main_Menu: //call the main menu functions //Game::MainMenu(); break; case Game_State_Options_Menu: //call the options menu functions //Game::OptionsMenu(); break; case Game_State_Game_Menu: //call the functions for the game menu //Game::GameMenu(); break; case Game_State_Render: //call the main rendering sequence Render::RenderMainScene(); break; default: //call the default function, the rendering loop Render::RenderMainScene(); break; } // return success return(1); } 
Now VC++ is giving me some nasty errors regarding this loop (or so it says). Here they are: D:\STYDX7IN24\Source\lightworks\functions.cpp(97) : error C2143: syntax error : missing '':'' before '';'' D:\STYDX7IN24\Source\lightworks\functions.cpp(97) : error C2143: syntax error : missing '';'' before '':'' D:\STYDX7IN24\Source\lightworks\functions.cpp(101) : error C2143: syntax error : missing '':'' before '';'' D:\STYDX7IN24\Source\lightworks\functions.cpp(101) : error C2143: syntax error : missing '';'' before '':'' D:\STYDX7IN24\Source\lightworks\functions.cpp(105) : error C2143: syntax error : missing '':'' before '';'' D:\STYDX7IN24\Source\lightworks\functions.cpp(105) : error C2143: syntax error : missing '';'' before '':'' D:\STYDX7IN24\Source\lightworks\functions.cpp(109) : error C2143: syntax error : missing '':'' before '';'' D:\STYDX7IN24\Source\lightworks\functions.cpp(109) : error C2143: syntax error : missing '';'' before '':'' Can anyone see what is wrong? I can''t (I really need to brush up on my C++). Never cross the thin line between bravery and stupidity.

Share on other sites
Heh... for starters, if that's a a method definition ( a method is a function inside a class ) and the :: operator tells me it is you have not included the function type.

If you have

class C_foo
{
public:
C_foo(); // constructor
~C_foo(); // desctructor

void MainLoop(); // main game loop
};

then your method definition must be

void C_foo::MainLoop()
{
// function code
}

This does not apply to constructors and destructors. And also you don't need it when calling function.

So for starters try that. Next check in your class defenition if did not forget the closing semi-colon ( after the last bracket. It might give some errors like that.

P.S. : you don't need that last break in your switch after the default. I don't think that could give you an error tough.

WHO DO THEY
THINK THEY'RE
FOOLING : YOU ?

GARAL website

Edited by - Bleakcabal on January 26, 2001 1:56:44 PM

Share on other sites
Then again, it may not be anything so wild...not to insult anybody''s intelligence, but the most obvious error I''ve seen listed, yet most often left unsolved, is to forget to put a semicolon after a struct or class definition. Seems like I read somewhere that''s not required, but it usually fixes problems, like

class CDuh{
private:
int iDuhVar1;
//other vars

public:
CDuh();
~CDuh();
}; <-- sometimes leaving that semicolon off generates several errors.

Maybe not it, but it''s worth a try if the other solution didn''t fix it...
--

WNDCLASSEX Reality;
...
...
Reality.lpfnWndProc=ComputerGames;
...
...
RegisterClassEx(&Reality);

Unable to register Reality...what''s wrong?
---------
Dan Upton
WolfHeart Software

Share on other sites
It turns out when I was declaring the Game_State_whatever things I was doing it like
  #define Game_State_Main_Menu = 1;

when I was supposed to be doing it like
  #define Game_State_Main_Menu = 1 //note the lack of a semicolon

That has got to be one of the wierdest things when you aren''t supposed to have a semicolon.

Thanks for trying to guess it anyway.

Never cross the thin line between bravery and stupidity.

Share on other sites
You shoudn''t have the ''='' there either

• Forum Statistics

• Total Topics
628728
• Total Posts
2984419

• 25
• 11
• 10
• 16
• 14