-
Freeze....
why does this freeze? Everything happens as it should but when I hit enter.... nothing hapens... any ideas?
Code:
void PlayerWin()
{
if(Current.gameover == 1)
{
Current2.score += 15000;
if(Current.score > Current2.score) Current.winner = 1;
else if(Current2.score > Current.score) Current2.winner = 1;
}
else if(Current2.gameover == 1)
{
Current.score += 15000;
if(Current.score > Current2.score) Current.winner = 1;
else if(Current2.score > Current.score) Current2.winner = 1;
}
Draw();
while(1 == 1)
{
if(Current.winner == 1)
{
draw_sprite(buffer, (BITMAP*)data[Win].dat, 40, 100);
draw_sprite(buffer, (BITMAP*)data[Lose].dat, 400, 100);
}
else if(Current2.winner == 1)
{
draw_sprite(buffer, (BITMAP*)data[Lose].dat, 40, 100);
draw_sprite(buffer, (BITMAP*)data[Win].dat, 400, 100);
}
blit(buffer, screen, 0, 0, 0, 0, 640, 480);
if(key[KEY_ENTER])
{
MainTitle();
}
}
}
-
That would depend largely on what "MainTitle()" does. That's a scary looking layout for it though. You would probably be better off removing that "if(key[KEY_ENTER])" chunk and changing the surrounding loop from "while(1 == 1)" to "while(!key[KEY_ENTER])".
Then put "MainTitle()" after the loop.
Does the program actually freeze (ie. crash) or does it simply get stuck in that while(1 == 1) loop?
-
it just gets stuck in the loop... and i have tried calling other functions and just simply breaking the loop and it sticks no matter what.... I will try the
Code:
while(!key[KEY_ENTER]
-
Two more ways to make an endless loop:
for (;;)
while (1)
It might be in some of your other functions. I haven't used Allegro in over a year, so I forget the keyboard functions.
Did you install the keyboard correctly? Does the install_keyboard() give any errors?
-
yeah I have other loops just like this one but this one just wont break....
-
What does MainTitle() do?
It looks (from what little is shown here), like this continuous loop should not exist at all. The only way your program would be able to terminate is if MainTitle() kills it at some point. Usually a continuous loop is a bad practice. It should be shunned almost as much as a goto command.
What is the purpose of that loop anyway? Given the nature of this function, I would assume that it's not one of the primary ones in your program but merely a tool for displaying who wins and looses - is that right? If so, then that loop looks very out of place.
I guess the main questions here are:
- What does MainTitle() do?
- Why is that loop there at all?
- When does PlayerWin() get called?
-
MainTitle() clears the bitmap and displays the title screen... I have called this from other loops and it works fine...
the loop is there to freeze the gameplay while the Win and Lose signs are displayed
PlayerWin gets called when gameover is detected....
-
ok I fixed it...
I just used a variable throughout the hold the whole program so I could get rid of the loop...