Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / illegal else/if statement

Author
Message
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 12th Oct 2009 15:05
could someone please help me understand as to how and why this statement
brings up the following rror message and how i could write it differently...
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 12th Oct 2009 15:07
sry... here is the error message:
initiate.cpp(93) : error C2181: illegal else without matching if
initiate.cpp(98) : error C2181: illegal else without matching if

oh yeah ignore the closing bracket at the end there (on the code snippet lol thanks in advance
Chamill
16
Years of Service
User Offline
Joined: 29th Sep 2008
Location:
Posted: 12th Oct 2009 15:10
Remove the ";" at the end of each 'if' line =)

Cuz in that case, u tell the if statement to do nothing =D

Chamillion

You can only get smarter by playing a smarter opponent.
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 12th Oct 2009 21:57 Edited at: 12th Oct 2009 21:59


Here's so you can copy and paste

if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 13th Oct 2009 14:01
thanks alot guys u don't know how much that helped, i used to have that code setup differently and it never worked, than i tried that and got an error message but thanks to u (SFCBias and Chamill) my simple (very simple!!!) game now gives the player a certain amount of lives, again, thanks alot
Chamill
16
Years of Service
User Offline
Joined: 29th Sep 2008
Location:
Posted: 13th Oct 2009 19:47
Lol mate, our help couldnt be less

Any other question? Feel free to ask.

Chamillion

You can only get smarter by playing a smarter opponent.
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 13th Oct 2009 21:56
That why we're here

if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 14th Oct 2009 13:17
thnx alot guys but i nedd one more thing: does anyone know a command that will enable me to call/open an exe file (made in vb if that makes a difference) that will then replace (as in close) my program.
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 14th Oct 2009 13:18
the file is called load.exe if that helps
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 14th Oct 2009 13:20
and i tried doing this but it dosen't close my program it just keeps on opening up load.exe:


here is the code for _CloseDown()
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 14th Oct 2009 13:44 Edited at: 14th Oct 2009 13:46
well I do recommend using ShellExecute, but it looks like you didnot use the right params,and truly i beleive you can pass in NULL for all the params execpt the int dCmdShow, and the filename.So try...

make sure you put it in the right directory

alternatively , you could use


if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 14th Oct 2009 14:04
thanks very much
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 14th Oct 2009 14:22
by the way, thanks for posting back so fast SFCBias
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 14th Oct 2009 14:27
lol thanks alot it works really well but my program does not close no matter what i do, here is code:



here is code for _CloseDown();

SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 14th Oct 2009 21:58 Edited at: 14th Oct 2009 22:00
where is this function located in your code

if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 15th Oct 2009 11:01
the function closedown is located in main.cpp after all of my other functions have finished and it is only activated if the escape key is pressed as well as in the piece of code above (right down the bottom next to return
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 15th Oct 2009 13:45 Edited at: 15th Oct 2009 13:50
Sorry i should have been more specific, i meant where is the void Dead(void) ?

If your trying to close down the program completely , you must call the return from within the while ( LoopGDK() ) loop which will then send you back to void DarkGDK (void) where then i think you should call _CloseDown(); and then your program should exit successfully

if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;
How is it going
17
Years of Service
User Offline
Joined: 18th Sep 2007
Location: California
Posted: 16th Oct 2009 06:23
isn't the void Dead(void) being declared in the first line...
void Dead(void) *************
{

for ( int i = 1; i < 500; i++ )

dbDeleteSprite ( i );

for ( int i = 1; i < 500; i++ )

dbDeleteImage ( i );
for ( int i = 1; i < 500; i++ )
dbDeleteMusic ( i );
for ( int i = 1; i < 500; i++ )
dbDeleteSound ( i );
dbText (500 , 230, "GAME OVER");
dbSync ( );
dbSync ( );
dbSync ( );
dbSync ( );
dbSync ( );
dbSync ( );
dbSync ( );


ShellExecute(NULL,"open","./load.exe",NULL,NULL,SW_SHOWNORMAL);
_CloseDown();
return;


}

think he's missing a main loop some how...
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 16th Oct 2009 13:47
@How is it Going, you need to put code in code tags , also i think that void dead is in the main loop which would explain the constant opening of load.exe

if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 16th Oct 2009 15:54
its working great now but i have one small problem, my game is a 2d space shooter in which the player must destroy asteroids. my problem is that i have an explosion sheet and some code that should work (to make an explosion) but it bloody well dosn't what happens is that every time the missile (the sprite b) hits an asteroid (the sprite i), instead of playing the animation i've loaded it just plays one picture or frame from it every time i shoot an asteroid so basically it cycles through frames every time the asteroid and missile collide here is code and attatched is explosion sheet: (also if u know a way that will delete the bullet for me than please tell me, i've tried dbHideSprite and dbDeleteSprite as well as just repositioning it with dbSprite)
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 16th Oct 2009 16:44
here is explosion sheet sry..

Attachments

Login to view attachments
Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 16th Oct 2009 19:32
You need to add a check to see if the animation is already playing so it doesnt just start again every time.



Code is for another project i have but you get the point. Sorry for wierd formatting.
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 17th Oct 2009 08:23
but don't i want it to start again every time, the animation is an explosion and i want it to play every time i hit an asteroid with a missile, as it is it just cycles through one frame every time i hit an asteroid. for instance: i hit one asteroid, it plays the first frame of the explosion and then the frame stays there until i hit another asteroid and it plays the second frame and so on and so forth lol this is not what i want to happen i want the whole animation to play every time my bullet/missile hits an asteroid
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 17th Oct 2009 12:53 Edited at: 17th Oct 2009 12:58
The catch here is that dbPlaySprite does NOT play the animation from beginning to end. It has to be repeatedly called, every loop, until the animation finishes. With an animated sprite, you can check if the currently displayed frame (dbSpriteFrame) is the last frame of the animation. If yes, you can stop playing the sprite, otherwise call dbPlaySprite again.

The delay value that you can give to the animated sprite helps because you don't need to calculate how many loops a picture has to be displayed before you change to the next picture of the animation (in other words, it does the timing for you), but that's the only help. In other ways the procedure is not much different from displaying several separate images after each other.

By the way, you don't need to recreate the animated sprite at every collision. It's enough to create it once when your sprites and images are initialized.
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 17th Oct 2009 16:16
ok so um (sry but i'm almost a complete novice at this) if i read ur post correctly this should work right (because it dosen't):
all this does is the same thing as before, what am i doing wrong????
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 17th Oct 2009 18:06 Edited at: 17th Oct 2009 18:07
he saying you need to call dbPlaySprite ONCE every loop until the animation is at the end, then you can stop the call.

e.g.Something like this in you main loop


With this you need to initialize a local boolean var to false (bool bPlayerHit = false

Then when ever you want the animation to play do bPlayerHit = !bPlayerHit OR bPlayerHit = true;

You will need to check what the current animation is and when it reaches the end reset bPlayerHit to false

if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;
How is it going
17
Years of Service
User Offline
Joined: 18th Sep 2007
Location: California
Posted: 17th Oct 2009 20:44
oh... miss read, sry.
10521
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location:
Posted: 18th Oct 2009 04:32
this is my code and it still dosen't work!


here is the code for collision detection:
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Oct 2009 14:13
You should check the return value of dbSpriteFrame. With that code you don't check which frame is displayed, only that the frame index is different from zero - which it will always be.



Remarks: You may need to add a blank frame at the end of the explosion animation and check for 13 instead of 12, because if the animation is stopped when frame 12 is reached, then frame 12 will never be displayed for more than a split second. It will also be necessary to hide or delete the sprite (depending on your game design) when bPlayerHit changes to false.

Also, this may work for one explosion, but if you have several explosions on the screen at the same time, then instead of the one variable bPlayerHit, you will need an array to keep track of the status of each explosion animation, and of course several sprite numbers to display all of them.

Login to post a reply

Server time is: 2024-10-01 14:38:03
Your offset time is: 2024-10-01 14:38:03