Game Freeze after pressing key in GUI (SOLVED)

Started by Sektor 13, Tue 22/02/2005 21:13:16

Previous topic - Next topic

Sektor 13

!!!!!!! EDIT: SOLVED !!!!!!!

ok i made custom GUI for QUIT window, i made that CTRL-Q opens it and if you CLICK quit game it quits, normaly, if you click cancel it goes back to the game, ok, and game works normaly, BUT if you hit any keyboard key while QUIT GUI is opened and than click cancel i cannot move character anymore, sometimes even CTRL-Q doesn't work anymore.. ?? Same problem is with SAVE and LOAD gui ...

here is code for GUIs (if it is enough ..:

Code: ags

 
//-------QUIT MENU----------------
if (interface == QUITM) {
  if (button == 0) {
    QuitGame(0);
  }
  if (button == 1) {
    GUIOff(2);
    UnPauseGame();
  }
  }



//--------START MENU BUTTONS ------------

if (interface == MENUBUTT) {
  if (button == 0) {
      GUIOn(4);
      Wait(20);
      GUIOn(5);
      Wait(23);
      GUIOff(5);
      GUIOn(6);
      Wait(20);
      GUIOff(3);
      GUIOff(4);
      GUIOff(5);
      GUIOff(6);
      GUIOff(7);
      NewRoom(4);
      
    }
  else if (button == 1)   // load game
      RestoreGameDialog();
    else if (button == 2)   // quit
      QuitGame(1);
}
//------------HUD-----------------

if ((interface == HUD)  && (IsGUIOn(2) ==0)){
  
if ((button == 1) && (IsGUIOn(9) ==0)) {
    GUIOn(9);
    }
    
else if ((button == 1) && (IsGUIOn(9) ==1)) {
    GUIOff(9);
  }
  
if (button == 6){
    GUIOn(0);
    }
    
    if (button == 7){
    GUIOn(1);
 }

    
 
 
  if ((button == 3) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed))
      game.top_inv_item = game.top_inv_item + (game.num_inv_displayed/2);
    if ((button == 4) && (game.top_inv_item > 0))
      game.top_inv_item = game.top_inv_item - (game.num_inv_displayed/2);
    }

   
//-----------RADIO HUD-----------------
   
if ((interface == HUDRADIO) && (IsGUIOn(2) ==0)) {
 
if (button == 0)  {
  SetCharacterView (JACK,4);
  SetCharacterSpeechView(JACK,5);
  AnimateCharacter(JACK,1,5,0);
  Wait(25);
  SetCharacterView (JACK,5);
  Wait(16);
  GUIOn(10);
  RunDialog(0);     }

 if (button == 1) {
  SetCharacterView (JACK,4);
  SetCharacterSpeechView(JACK,5);
  AnimateCharacter(JACK,1,5,0);
  Wait(25);
  SetCharacterView (JACK,5);
  Wait(16);
  GUIOn(10);
  RunDialog(1);     }

 if (button == 2) {
  SetCharacterView (JACK,4);
  SetCharacterSpeechView(JACK,5);
  AnimateCharacter(JACK,1,5,0);
  Wait(25);
  SetCharacterView (JACK,5);
  Wait(16);
  GUIOn(10);
  RunDialog(2);     }
    
}

//-----------------------------------------------------

//	Restore game GUI
//-----------------------------------------------------
 if (interface == LOADA) {
    if (button ==2) GUIOff(LOADA); //cancel
    if (button ==1){ //click on listbox item
       int index = ListBoxGetSelected(LOADA,1);
       if (GetSaveSlotDescription(index+100,buffer)==1){ //if there is a savegame here
         GUIOff(LOADA);
         RestoreGameSlot(index+100); 
        }
       } 
 if (button == 3){ //scroll up
         if (GStopsaveitem<5) GStopsaveitem=0;
         else GStopsaveitem-=5;
      ListBoxSetTopItem(LOADA,1,GStopsaveitem);
      }
    if (button == 4 && GStopsaveitem<90) //scroll down
      GStopsaveitem+=5;
      ListBoxSetTopItem(LOADA,1,GStopsaveitem);
    }    

  
//-----------------------------------------------------

//	Save game GUI
//-----------------------------------------------------

 if (interface == SAVEA){
    int index=ListBoxGetSelected(SAVEA,1);
    if (button == 3){//cancel
      GUIOff(SAVEA);
      GUIOff(SAVETEXTBOX);
    }
    if (button == 1){ //click on listbox
     int stbypos;
      StrFormat(buffer,"%d.",index+1);
      SetLabelText(SAVETEXTBOX,1,buffer);
      if (GetSaveSlotDescription(index+100,buffer)==0) StrCopy(buffer,"");//GetSaveSlotDescription(index+100,buffer);
      //else StrCopy(buffer,"");
     SetTextBoxText(SAVETEXTBOX,0,buffer);
     stbypos=28+((index-GStopsaveitem)*(DEFAULT_FONT_HEIGHT+2)); //28 is set by trial-error. Deppends of the savegames listbox position
     if (index<9)  SetGUIObjectPosition(SAVETEXTBOX, 0, 12, 0);
     else SetGUIObjectPosition(SAVETEXTBOX, 0, 18, 0);     
     SetGUIPosition(SAVETEXTBOX,29,stbypos);// 29 is set by trial-error. Same as above.
     GUIOn(SAVETEXTBOX);
    }
    if (button == 2 && index>=0) { //save
      GetTextBoxText(SAVETEXTBOX,0,buffer);
      GUIOff(SAVEA);
      GUIOff(SAVETEXTBOX);
      SaveGameSlot(index+100,buffer);
    } 
     if (button == 4){// scroll up
       GUIOff(SAVETEXTBOX);
       ListBoxSetSelected(SAVEA,1,-1);
         if (GStopsaveitem<5) GStopsaveitem=0;
         else GStopsaveitem-=5;
       ListBoxSetTopItem(SAVEA,1,GStopsaveitem);
    }
    if (button == 5 && GStopsaveitem<90){ //scroll down
       GUIOff(SAVETEXTBOX);
       ListBoxSetSelected(SAVEA,1,-1);
       GStopsaveitem+=5;
       ListBoxSetTopItem(SAVEA,1,GStopsaveitem);
    }
    
  }
 if (interface == SAVETEXTBOX){
    int index=ListBoxGetSelected(SAVEA,1);
    if (button == 0){
      GetTextBoxText(SAVETEXTBOX,0,buffer);
      GUIOff(SAVEA);
      GUIOff(SAVETEXTBOX);
      SaveGameSlot(index+100,buffer);
    }
    if (IsButtonDown(RIGHT)) GUIOff(SAVETEXTBOX);  
 }
//-----------------------------------------------------




Sektor 13

#1
hhmm actualy if i press any (alphabet) key anytime in the game character freezes, but i can open GUI s.



EDIT: Nevermind, i found out what was wrong..

if (keycode==17)  GUIOn(2); PauseGame();            <-- i forgot to delete that pause game... hmm, but still strange that any key paused the game... :-*

strazer

#2
Glad you were able to solve it.
While checking braces, I made a more readable version of the above:

Code: ags

  if (interface == QUITM) {

	if (button == 0) {
		QuitGame(0);
	}

	if (button == 1) {
		GUIOff(2);
		UnPauseGame();
	}

  }


  //--------START MENU BUTTONS ------------

  if (interface == MENUBUTT) {

	if (button == 0) {
		GUIOn(4);
		Wait(20);
		GUIOn(5);
		Wait(23);
		GUIOff(5);
		GUIOn(6);
		Wait(20);
		GUIOff(3);
		GUIOff(4);
		GUIOff(5);
		GUIOff(6);
		GUIOff(7);
		NewRoom(4);
	}

	else if (button == 1)   // load game
		RestoreGameDialog();

	else if (button == 2)   // quit
		QuitGame(1);
  }


  //------------HUD-----------------

  if ((interface == HUD) && (IsGUIOn(2) == 0)) {

	if ((button == 1) && (IsGUIOn(9) == 0)) {
		GUIOn(9);
	}
	else if ((button == 1) && (IsGUIOn(9) == 1)) {
		GUIOff(9);
	}
 
	if (button == 6) {
		GUIOn(0);
	}
   
	if (button == 7) {
		GUIOn(1);
	}


	if ((button == 3) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed))
		game.top_inv_item = game.top_inv_item + (game.num_inv_displayed / 2);

	if ((button == 4) && (game.top_inv_item > 0))
		game.top_inv_item = game.top_inv_item - (game.num_inv_displayed / 2);

  }


  //-----------RADIO HUD-----------------
   
  if ((interface == HUDRADIO) && (IsGUIOn(2) == 0)) {

	if (button == 0)  {
		SetCharacterView (JACK, 4);
		SetCharacterSpeechView(JACK, 5);
		AnimateCharacter(JACK, 1, 5, 0);
		Wait(25);
		SetCharacterView (JACK, 5);
		Wait(16);
		GUIOn(10);
		RunDialog(0);
	}

	if (button == 1) {
		SetCharacterView (JACK, 4);
		SetCharacterSpeechView(JACK, 5);
		AnimateCharacter(JACK, 1, 5, 0);
		Wait(25);
		SetCharacterView (JACK, 5);
		Wait(16);
		GUIOn(10);
		RunDialog(1);
	}

	if (button == 2) {
		SetCharacterView (JACK, 4);
		SetCharacterSpeechView(JACK, 5);
		AnimateCharacter(JACK, 1, 5, 0);
		Wait(25);
		SetCharacterView (JACK, 5);
		Wait(16);
		GUIOn(10);
		RunDialog(2);
	}
   
  }


  //-----------------------------------------------------
  // Restore game GUI
  //-----------------------------------------------------

  if (interface == LOADA) {

	if (button == 2) GUIOff(LOADA); // cancel

	if (button == 1) { // click on listbox item
		int index = ListBoxGetSelected(LOADA,1);
		if (GetSaveSlotDescription(index+100,buffer) == 1) { // if there is a savegame here
			GUIOff(LOADA);
			RestoreGameSlot(index+100);
		}
	}

	if (button == 3) { // scroll up
		if (GStopsaveitem < 5) GStopsaveitem = 0;
		else GStopsaveitem -= 5;
		ListBoxSetTopItem(LOADA, 1, GStopsaveitem);
	}

	if (button == 4 && GStopsaveitem < 90) // scroll down
// BRACES MISSING HERE?
		GStopsaveitem += 5;

	ListBoxSetTopItem(LOADA, 1, GStopsaveitem);

  }   


  //-----------------------------------------------------
  // Save game GUI
  //-----------------------------------------------------

  if (interface == SAVEA) {

	int index = ListBoxGetSelected(SAVEA, 1);

	if (button == 3) { // cancel
		GUIOff(SAVEA);
		GUIOff(SAVETEXTBOX);
	}

	if (button == 1) { // click on listbox
		int stbypos;
		StrFormat(buffer, "%d.", index+1);
		SetLabelText(SAVETEXTBOX, 1, buffer);
		if (GetSaveSlotDescription(index+100, buffer) == 0)
			StrCopy(buffer, ""); // GetSaveSlotDescription(index+100, buffer);
		//else StrCopy(buffer, "");
		SetTextBoxText(SAVETEXTBOX, 0, buffer);
		stbypos = 28 + ((index-GStopsaveitem)*(DEFAULT_FONT_HEIGHT+2)); //28 is set by trial-error. Depends of the savegames listbox position
		if (index < 9)  SetGUIObjectPosition(SAVETEXTBOX, 0, 12, 0);
		else SetGUIObjectPosition(SAVETEXTBOX, 0, 18, 0);     
		SetGUIPosition(SAVETEXTBOX, 29, stbypos); // 29 is set by trial-error. Same as above.
		GUIOn(SAVETEXTBOX);
	}

	if (button == 2 && index >= 0) { // save
		GetTextBoxText(SAVETEXTBOX, 0, buffer);
		GUIOff(SAVEA);
		GUIOff(SAVETEXTBOX);
		SaveGameSlot(index+100, buffer);
	}

	if (button == 4) { // scroll up
		GUIOff(SAVETEXTBOX);
		ListBoxSetSelected(SAVEA, 1, -1);
		if (GStopsaveitem < 5) GStopsaveitem = 0;
		else GStopsaveitem -= 5;
		ListBoxSetTopItem(SAVEA, 1, GStopsaveitem);
	}

	if (button == 5 && GStopsaveitem < 90) { // scroll down
		GUIOff(SAVETEXTBOX);
		ListBoxSetSelected(SAVEA, 1, -1);
		GStopsaveitem += 5;
		ListBoxSetTopItem(SAVEA, 1, GStopsaveitem);
	}
 
  }

  if (interface == SAVETEXTBOX) {

	int index = ListBoxGetSelected(SAVEA, 1);

	if (button == 0) {
		GetTextBoxText(SAVETEXTBOX, 0, buffer);
		GUIOff(SAVEA);
		GUIOff(SAVETEXTBOX);
		SaveGameSlot(index+100, buffer);
	}

	if (IsButtonDown(RIGHT)) GUIOff(SAVETEXTBOX);

  }


  //-----------------------------------------------------


I think you're missing braces at button 4 of LOADA?

Edit:

Quote
if (keycode==17)  GUIOn(2); PauseGame();            <-- i forgot to delete that pause game... hmm, but still strange that any key paused the game...

Well, since PauseGame is not within braces, like

Code: ags

  if (keycode == 17) {
	GUIOn(2);
	PauseGame();
  }


it gets called everytime any key is pressed...

Sektor 13

yes my scripts are readable as hyrogliphs  ;D i noticed that too  ;D

monkey0506

Quote from: Sektor 13 on Tue 22/02/2005 21:18:27
if (keycode==17)  GUIOn(2); PauseGame();            <-- i forgot to delete that pause game... hmm, but still strange that any key paused the game... :-*

Actually, if your code was written exactly like that (with no brackets), then any time on_key_press was called it would pause the game:

Code: ags
function on_key_press(int keycode) {
// stuff
if (keycode == 17) GUIOn(2); // this line ends here, after the semicolon
PauseGame(); // as soon as this line is reached, Pause the game (i.e., your problem)
// stuff
}


No matter what key you pressed, PauseGame was called every time that on_key_press was called.  Thefore, no matter what key you pressed, it would pause the game.  You would have needed brackets to only pause the game on keycode 17:

Code: ags
// on_key_press
// stuff
if (keycode == 17) [b]{[/b]
  GUIOn(2);
  PauseGame();
  [b]}[/b]


See the difference?  And by the way, the game is automatically paused any time a Popup Modal GUI is turned on (which I'm presuming GUI 2 is).  ;)

Sektor 13

yes i know, that it is paused if popout modal is selected, but you can still press other GUI buttons and they work, so i had some problems, i modified my GUI scripts so it workk fine now. But if you use default QUIT GAME menu you cannot press any buttons at all, just QUIT an PLAY !..

SMF spam blocked by CleanTalk