Freeze....

This is a discussion on Freeze.... within the Game Programming forums, part of the General Programming Boards category; why does this freeze? Everything happens as it should but when I hit enter.... nothing hapens... any ideas? Code: void ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    16

    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();
        }
      }
    }

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    4
    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?

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    16
    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]

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    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?

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    16
    yeah I have other loops just like this one but this one just wont break....

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    4
    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?

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    16
    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....

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    16
    ok I fixed it...

    I just used a variable throughout the hold the whole program so I could get rid of the loop...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strlen causing my program to freeze
    By Beowolf in forum C Programming
    Replies: 2
    Last Post: 09-11-2007, 05:09 PM
  2. Pipeline freeze simulation
    By darklightred in forum C Programming
    Replies: 2
    Last Post: 07-24-2006, 12:57 PM
  3. LoadFromFile() causes Windows 98 to freeze?
    By MidnightlyCoder in forum Windows Programming
    Replies: 8
    Last Post: 03-17-2006, 02:23 PM
  4. computer freeze up
    By nbo10 in forum Tech Board
    Replies: 9
    Last Post: 10-09-2005, 02:39 PM
  5. Freeze the screen
    By chris1985 in forum Windows Programming
    Replies: 3
    Last Post: 01-13-2005, 07:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21