GUI freezes up

Started by Anarcho, Sun 14/08/2005 17:48:00

Previous topic - Next topic

Anarcho

I've been testing a new GUI and it was almost working, but now when I call up anything---the quit , load and save GUI, the proper screen will appear, but none of the buttons will work.  My script is sort of a mish-mash of stuff I've gotten from various posts---and it sure isn't pretty.  I've looked through it a number of times for missing/misplaced brackets, and I fixed one...but I can't see anything else that is wrong with it.  Help!

My GUI script:

if (interface == ICONBAR) {
    if (button == 4) {  // show inventory
      show_inventory_window();
    }
    else if (button == 5) {   // use selected inventory
      if (character[ GetPlayerCharacter() ].activeinv >= 0)
         SetCursorMode(4);
    }
    else if (button == 6) {   // save game
         
      ListBoxSaveGameList(7,2); // Fill List Box with saved games
      SetCursorMode(6);
      GUIOn(SAVE);                   // Bring Save interface on             
    }
         
    else if (button == 7) {   // load game
      SetCursorMode(6);
      ListBoxSaveGameList(4,0);
      GUIOn(LOADGUI);
     
    }
    else if (button == 8) {  // quit
      SetCursorMode(6);
      GUIOn(QUITGUI);
    }
    else if (button == 9)    // about
      Display("EMILY ENOUGH: IMPRISONED[by Logan Worsley Adventure Game Studio v2 run-time engine[Copyright (c) 1999-2003 Chris Jones");
    // end if interface ICONBAR

    if (interface == INVENTORY) {
    // They clicked a button on the Inventory GUI
   
    if (button == 1) {
      // They pressed SELECT, so switch to the Get cursor
      SetCursorMode (MODE_USE);
      // But, override the appearance to look like the arrow
      SetMouseCursor (6);
    }
   
    if (button == 2) {
      // They pressed LOOK, so switch to that mode
      SetActiveInventory(-1);
      SetCursorMode(MODE_LOOK); 
    }
    if (button == 3) {
      // They pressed the OK button, close the GUI
      GUIOff (INVENTORY);
      SetDefaultCursor();
    }

    if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) {
      // scroll down
      game.top_inv_item = game.top_inv_item + game.items_per_line;
    }
    if ((button == 5) && (game.top_inv_item > 0)){
      // scroll up
      game.top_inv_item = game.top_inv_item - game.items_per_line;
    }
  }


  if (interface == QUITGUI) {   
    if (button == 1) {
      QuitGame(0);
    }
    if (button == 2) {
      GUIOff(QUITGUI);
      Mouse.UseDefaultGraphic();
    }
  } 
//INTERFACE SAVE GAME

    if (interface == SAVE) {
     // List element was clicked, copy selected item's text to the TextBox
  if (button==2) {
     bg_save_idx = ListBoxGetSelected(SAVE,2);
     ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
     if (StrComp(bg_save_buf,"<new>")==0) StrCopy(bg_save_buf,"");
     SetTextBoxText(SAVE,3,bg_save_buf);
  }

  // SAVE button was pressed, save the game
  else if (button==0) {
     SetRestartPoint();                 // Restart here
     bg_save_idx=ListBoxGetSelected(SAVE,2); // Save game in new save game slot
     ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
     if (StrComp(bg_save_buf,"<new>")==0) {   
        bg_save_slot = ListBoxGetNumItems(SAVE,2);
        GetTextBoxText(SAVE,3,bg_save_buf); 
        if (StrComp(bg_save_buf,"")==0) StrFormat(bg_save_buf,"Game-%d",bg_save_slot);
     }
     else {                             // Over-write an existing save game
        bg_save_slot=savegameindex[bg_save_idx]; // slot with name from textbox.
        GetTextBoxText(SAVE,3,bg_save_buf); 
       if (StrComp(bg_save_buf,"")==0) ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
     }
     GUIOff(SAVE);          // Close dialog amd return
     //TURN ON NORMAL GAME GUIs HERE
     SaveGameSlot(bg_save_slot, bg_save_buf); // Perform save operation last otherwise
     //Display("Saved as: %s", bg_save_buf);    // SAVE dialog will be active on restore
  }

  // CANCEL button was pressed, cancel operation
  else if (button==1) {
     GUIOff(SAVE);          // Close dialog and return
     //TURN ON NORMAL GAME GUIs HERE
  }
}

//INTERFACE 6 - RESTORE GAME

if (interface == LOADGUI) {
  // CANCEL button was pressed, cancel operation
   if (button==1) {
     Mouse.UseDefaultGraphic();
     GUIOff(LOADGUI);       // Close dialog and return

     //TURN ON NORMAL GAME GUIs HERE
  }

  // RESTORE button was pressed, restore the game
  else if (button==0) {
     bg_restore_idx=ListBoxGetSelected(LOADGUI,2); // Perform save operation
     if (bg_restore_idx==-1) {          // No selection, nothing to restore
        Display("Please make a selection first...");
     }
     else                               // Ok continue restoring game
     {
        ListBoxGetItemText(LOADGUI,2,bg_restore_idx,bg_restore_buf);
        RestoreGameSlot(savegameindex[bg_restore_idx]);
        //Display("Restored from: %s",bg_restore_buf);
        Mouse.UseDefaultGraphic();
        GUIOff(LOADGUI);
     }
   
    if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) {
      // scroll down
      game.top_inv_item = game.top_inv_item + game.items_per_line;
    }
    if ((button == 3) && (game.top_inv_item > 0)){
      // scroll up
      game.top_inv_item = game.top_inv_item - game.items_per_line;
    }

  }
}
}


Ashen

#1
If that's exactly the script you've got, I think you're missing a '}' after button 9 on ICONBAR:

   //..blah blah blah
    else if (button == 8 ) {  // quit
      SetCursorMode(6);
      GUIOn(QUITGUI);
    }
    else if (button == 9)    // about
      Display("EMILY ENOUGH: IMPRISONED[by Logan Worsley Adventure Game Studio v2 run-time engine[Copyright (c) 1999-2003 Chris Jones");
   <===SHOULD BE HERE-ISH===> // end if interface ICONBAR

    if (interface == INVENTORY) {
    // They clicked a button on the Inventory GUI
   //...etc

As is, it looks like INVENTORY, QUITGUI, SAVE and LOAD GUI are all being checked in if (interface == ICONBAR, and so won't work. You may also need to knock a '}' off the end to compensate - not sure about that though, and can't be bothered matching all the braces to check.

EDIT:
I just checked and you will need to take off the last '}'.
I know what you're thinking ... Don't think that.

Anarcho

Ok, thanks Ashen.  I got the buttons working again on the inventory and quit GUIs, but now when I call up the Save GUI, and type in a save game name and hit the save button I get this error:

ListBoxGetItemText: invalid item specified.

This is for line 470 which is:   ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);

Now like I said, I sorta pieced this script together from various posts.  And it's using the pre 2.7 version of AGS.  When I look up ListBoxGetItemText in the manual, it says it's obsolete and doesn't describe the old function.  So I'm not sure what the above code even means.  Does the 2 after SAVE refer to a GUI control?  My Save GUI is GUI 7 and the listbox is control 2--does that even matter in this code?

I know this is the worst way to do a GUI, but I haven't been able to find a good tutorial on Save/Load guis---especially using version 2.7 .  And the manual only gives a tutorial on making a Quit GUI---which I've already figured out how to do.


Ashen

#3
Quote from: The Manual
ListBoxGetItemText
ListBoxGetItemText (int gui, int object, int item, string buffer)

Fills BUFFER with the text from list item number ITEM in listbox OBJECT on gui GUI. This is useful for finding out the name of the option the user selected.
Remember that list box items are numbered starting from 0, so the first item is 0, the second is 1, and so on.

Example:

string buffer;
ListBoxGetItemText (2,3,ListBoxGetSelected(2,3),buffer);

will get the text of the selected item in listbox 3 of GUI 2.

So, 'SAVE' refers to the GUI, '2' to the control (the listbox), 'bg_save_idx' to the selected save slot and 'bg_save_buf' to the string to send the text to.
I'd guess the problem is with the bg_save_idx, that being the item number (ListBoxGetItemText: invalid item specified.). It sounds like you're trying to get the description of a slot that doesn't exist - is there a slot selected when you get the error? If not, that might be your problem - try replacing it with if (bg_save_idx != -1) ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf); - should only run if a valid slot is selected.

If there is a save slot selected - I don't know what to suggest.
I know what you're thinking ... Don't think that.

Anarcho

#4
Ok, I actually ended up using a different script because that one wasn't working.  It all works now!  That was a frustrating process. 


SMF spam blocked by CleanTalk