Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: poc301 on Mon 08/11/2004 21:46:33

Title: Trouble with two inventories (they both pop up...) Code Inside (SOLVED)
Post by: poc301 on Mon 08/11/2004 21:46:33
I am using a two inventory system with my game.Ã,  One (with the main EGO character) for normal inventory stuff, and another for spells (with a 2nd character SPELLS).

The spells inventory (with Char SPELLS) works fine.Ã,  It opens, displays properly, and closes (although the selected spell doesn't carry back over to EGO when the switch is done, but thats something else I will worry about later.

When I open the standard inventory screen (a custom one) for EGO, it opens fine, but it also opens the spell GUI screen!?Ã,  The inventory reflected on both the inventory and spell GUI is the inventory of EGO, so its pulling the right data.Ã,  However, I can NOT turn off the spell GUI for the life of me.Ã,  I have tried inserting GUIOff(x) commands throughout the code in both Global Script, and the GUI script.Ã, 

It is infuriating. I have included code, and would appreciate any insight into why this is happening, and how I can fix it.

Thanks!


---------------------------
GLOBAL CODE :
---------------------------

#sectionstart game_startÃ,  // DO NOT EDIT OR REMOVE THIS LINE

function game_start() {
SetInvDimensions (40,40) ;

// called when the game starts, before the first room is loaded

SetPlayerCharacter(4);Ã,  //The SPELL Character
AddInventory(3);Ã,  Ã, // The Zap Spell
AddInventory(4);Ã,  // The Detect Magic Spell
SetPlayerCharacter(0);Ã,  // Back to EGO character for the beginning of the game.


}
#sectionend game_startÃ,  // DO NOT EDIT OR REMOVE THIS LINE


function show_inventory_window () {
Ã, 

Ã,  // ** CUSTOM INVENTORY WINDOW
Ã,  GUIOn (3);Ã, Ã,  // Inventory GUI
Ã,  Ã, 
Ã,  // switch to the Use cursor (to select items with)
Ã,  SetCursorMode (MODE_USE);
Ã,  // But, override the appearance to look like the hand
Ã,  SetMouseCursor (6);

}



#sectionstart interface_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE

function interface_click(int interface, int button) {

if (interface == 4 && button == 18) {
Ã,  Ã,  GUIOn(1);Ã,  Ã, //SCORE GUI
Ã,  Ã,  GUIOff(4);Ã,  //INVENTORY GUI
Ã,  Ã,  Ã, }


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
Ã,  Ã,  Ã,  SaveGameDialog();
Ã,  Ã,  else if (button == 7)Ã,  Ã, // load game
Ã,  Ã,  Ã,  RestoreGameDialog();
Ã,  Ã,  else if (button == 8)Ã,  Ã, // quit
Ã,  Ã,  Ã,  QuitGame(1);

Ã,  Ã,  else if (button == 9)Ã,  Ã,  // SPELLS
SetPlayerCharacter (4);Ã,  //SPELLS CHARACTER
Ã,  Ã,  Ã,  GUIOn(6); //SPELLS MENU
Ã, 

}Ã,  // end if interface ICONBAR


if (interface == 6) {Ã,  // SPELLS INVENTORY GUI

if (button == 3) {Ã,  Ã, //CLOSE
SetPlayerCharacter(0);Ã, 
GUIOff(6);
Ã,  Ã,  Ã,  }
if (button == 2) {Ã,  //USE OR TAKE
Ã,  Ã, SetCursorMode(2);
Ã,  Ã, SetMouseCursor (6);
Ã,  Ã, }
}

Ã,  if (interface == GUI3) {Ã,  //GUI3 IS THE CUSTOM INVENTORY GUI
GUIOff(6);Ã,  // I TRIED PUTTING THIS ALL OVER THE PLACE, THIS IS THE MOST RECENT PLACE

// They clicked a button on the Inventory GUI
Ã,  Ã, 
Ã,  Ã,  if (button == 1) {
Ã,  Ã,  Ã,  // They pressed USE, so switch to the Get cursor
Ã,  Ã,  Ã,  SetCursorMode (3);
Ã,  Ã,  Ã,  // But, override the appearance to look like the hand
Ã,  Ã,  Ã,  SetMouseCursor (2);
Ã,  Ã,  }
Ã,  Ã, 
Ã,  Ã,  if (button == 2) {
Ã,  Ã,  Ã,  // They pressed TAKE, so switch to that mode
Ã,  Ã,  Ã,  SetCursorMode(2);
Ã,  Ã,  Ã,  SetMouseCursor (6);
Ã,  Ã,  }
Ã,  Ã,  if (button == 3) {
Ã,  Ã,  Ã,  // They pressed the OK button, close the GUI
Ã,  Ã,  Ã,  GUIOff (GUI3);
Ã,  Ã,  Ã,  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;
Ã,  Ã,  }
Ã,  }
}


------------------------------
END CODE
------------------------------


Help please! :)

Bill Garrett
Title: Re: Trouble with two inventories (they both pop up...) Code Inside
Post by: Ashen on Mon 08/11/2004 22:25:17
Well, the obvious thing is the missing braces:

    else if (button == 9)    // SPELLS
SetPlayerCharacter (4);  //SPELLS CHARACTER
      GUIOn(6); //SPELLS MENU

Should be:

    else if (button == 9)  {  //SPELLS
      SetPlayerCharacter (4);  //SPELLS CHARACTER
      GUIOn(6); //SPELLS MENU
    }


See if that helps.
The way you've got it now, it should open the SPELLS GUI whatever button you press (if it's set to 'Run Script', anyway).
Title: Re: Trouble with two inventories (they both pop up...) Code Inside
Post by: edmundito on Tue 09/11/2004 01:52:27
this has little with your problem, but it's a tip:

Instead of having:

SetPlayerCharacter(4);  //The SPELL Character
AddInventory(3);   // The Zap Spell
AddInventory(4);  // The Detect Magic Spell
SetPlayerCharacter(0);  // Back to EGO character for the beginning of the game.

you can have
AddInventoryToCharacter(4, 3);
AddInventoryToCharacter(4, 4);

Instead of switching characters back and forth....
Title: Re: Trouble with two inventories (they both pop up...) Code Inside
Post by: poc301 on Tue 09/11/2004 12:58:56
Thanks Ashen, that solved the issue.

Thanks netmonkey as well, that is much easier to do :)

Bill Garrett