Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: pslim on Mon 31/07/2006 22:43:48

Title: eMouseRight vs eMouseRightInv[SOLVED]
Post by: pslim on Mon 31/07/2006 22:43:48
Hey.

I'm trying to set up my custom inventory the way I want it, but I've run into problems when it comes to trying to allow the player to cycle through cursors while the inventory is up.

It seems that using button == eMouseRightInv only registers a click if the mouse is actually over an inventory item (so nothing happens if the inventory is empty, or if the click takes place in an empty portion). However, I can't seem to get button == eMouseRight to work at all while the inventory is up. Here's the code I'm trying to use:


#sectionstart on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
}

Ã,  Ã, if (button == eMouseLeft) {
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, mouse.Mode );
Ã,  }
Ã,  else if ((button == eMouseRight) && (gInventory.Visible == false)){Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  mouse.SelectNextMode();
Ã,  }Ã, 
Ã,  Ã,  else if ((button == eMouseRight) && (gInventory.Visible == true) &&Ã,  (Mouse.Mode == eModeLookat)) {
Ã,  Ã,  mouse.Mode = eModeInteract;
Ã,  Ã,  mouse.UseModeGraphic(eModePointer);
}Ã,  Ã, 
Ã,  else if ((button == eMouseRight) && (gInventory.Visible == true) &&Ã,  (Mouse.Mode == eModeUseinv)) {
Ã,  Ã,  mouse.Mode = eModeLookat;
}
Ã,  else if ((button == eMouseRight) && (gInventory.Visible == true) &&Ã,  (Mouse.Mode == eModeInteract)) {
Ã,  Ã,  mouse.Mode = eModeLookat;
}
else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeInteract)) {
Ã,  player.ActiveInventory=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
Ã,  Mouse.Mode=eModeUseinv;
}
else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeLookat)) {
Ã,  inventory[game.inv_activated].RunInteraction(mouse.Mode);
}
else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeUseinv)) {
Ã,  inventory[game.inv_activated].RunInteraction(mouse.Mode);
Ã, 
}
}


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


The left inventory code works fine, but nothing happens when I right-click while the inventory window is up. Although button == eMouseRightInv works, I'm not satisfied with only being able to cycle cursors while the mouse is over an inventory item. I want the player to be able to cycle no matter where their cursor is on the screen.

I would appreciate any help.Ã,  :-\
Title: Re: eMouseRight vs eMouseRightInv--Only over inventory items?
Post by: Ashen on Mon 31/07/2006 23:05:45
Is gInventory Popup Modal? Is so, on_mouse_click won't have any effect, due to the if(IsGamePaused()... condition at the top. You could try re-arranging the conditions, so the the gInventory.Visible conditions are run, or you could try using the on_event function instead (see this thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=25463.0)) - it might be less messing around.
Title: Re: eMouseRight vs eMouseRightInv--Only over inventory items?
Post by: Alynn on Tue 01/08/2006 07:10:13
Or,

if (gInvGui.Visible) {
//code here
}

then check if it's paused, then everything else.
Title: Re: eMouseRight vs eMouseRightInv--Only over inventory items?
Post by: pslim on Tue 01/08/2006 17:31:49
Hey guys. Thanks for the responses. I tried reordering things, and it compiles, but now it doesn't register any clicks while the inventory GUI is up, although it works fine when it's not. The code I've got is:

#sectionstart on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã, 
Ã,  if (gInventory.Visible == true) {


Ã,  Ã,  if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
}
Ã,  Ã,  else {

Ã,  Ã,  Ã,  if ((button == eMouseRight) &&Ã,  (Mouse.Mode == eModeLookat)) {
Ã,  Ã,  Ã,  Ã,  mouse.Mode = eModeInteract;
Ã,  Ã,  Ã,  Ã,  mouse.UseModeGraphic(eModePointer);
}Ã,  Ã, 
Ã,  Ã,  Ã,  else if ((button == eMouseRight) && (Mouse.Mode == eModeUseinv)) {
Ã,  Ã,  Ã,  Ã, mouse.Mode = eModeLookat;
}
Ã,  Ã,  Ã,  else if ((button == eMouseRight) &&Ã,  (Mouse.Mode == eModeInteract)) {
Ã,  Ã,  Ã,  Ã, mouse.Mode = eModeLookat;
}
Ã,  Ã,  Ã,  else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeInteract)) {
Ã,  Ã,  Ã,  Ã, player.ActiveInventory=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
Ã,  Ã,  Ã,  Ã, Mouse.Mode=eModeUseinv;
}
Ã,  Ã,  Ã,  else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeLookat)) {
Ã,  Ã,  Ã,  Ã, inventory[game.inv_activated].RunInteraction(mouse.Mode);
}
Ã,  Ã,  Ã,  else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeUseinv)) {
Ã,  Ã,  Ã,  Ã, inventory[game.inv_activated].RunInteraction(mouse.Mode);
Ã, 
}
}
}
Ã,  else {
Ã,  Ã, 
Ã,  Ã,  if (button == eMouseLeft) {
Ã,  Ã,  Ã,  Ã,  ProcessClick(mouse.x, mouse.y, mouse.Mode );
Ã,  }
Ã,  Ã, 
Ã,  Ã,  else if (button == eMouseRight) {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  Ã,  mouse.SelectNextMode();
Ã,  }Ã, 
Ã,  Ã,  else {
Ã,  }
Ã,  }



Ã,  }


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



I'm going to look carefully at the link Ashen posted but I guess I'm dragging my feet a little bit because it means starting over with my whole inventory arrangement, it seems.  :-\

But it may come to that, unless there's something obvious that I'm missing or have messed up on in the code above.
Title: Re: eMouseRight vs eMouseRightInv--Only over inventory items?
Post by: Ashen on Tue 01/08/2006 18:43:01
The way you've got the conditions now, it still won't run the Inventory stuff unless the game isn't paused, try:

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    if (gInventory.Visible == true) {
// Game paused, gInventory on - do stuff:
      if ((button == eMouseRight) &&  (Mouse.Mode == eModeLookat)) {
        mouse.Mode = eModeInteract;
        mouse.UseModeGraphic(eModePointer);
      }   
      else if ((button == eMouseRight) && (Mouse.Mode == eModeUseinv)) {
        mouse.Mode = eModeLookat;
      }
      else if ((button == eMouseRight) &&  (Mouse.Mode == eModeInteract)) {
       mouse.Mode = eModeLookat;
      }
      else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeInteract)) {
        player.ActiveInventory=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
        Mouse.Mode=eModeUseinv;
      }
      else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeLookat)) {
        inventory[game.inv_activated].RunInteraction(mouse.Mode);
      }
      else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeUseinv)) {
        inventory[game.inv_activated].RunInteraction(mouse.Mode);
      }
    }
    else {
// Game paused, gInventory not on - do nothing
    }
  }
  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
  else if (button == eMouseRight) {   // right-click, so cycle cursor
    mouse.SelectNextMode();
  }
}
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


I'm still not sure if it'll work, but the conditions should be better.

EDIT: Actually, I'm fairly sure it won't work, not entirely at least - on_mouse_click isn't called for clicks actually ON the GUI, even when you get the conditions right. So, you might have to use the on_event method (as well as this - although you could possibly call one from the other), or maybe run checks in rep_ex_always.
Title: Re: eMouseRight vs eMouseRightInv--Only over inventory items?
Post by: Alynn on Tue 01/08/2006 18:50:04
 if (gInventory.Visible == true) {
Ã,  Ã, if (IsGamePaused() == 1) {
Ã,  Ã,  Ã, // Game is paused, so do nothing (ie. don't allow mouse click)
Ã,  Ã, }
Ã,  Ã, else {


basically what you have told it to do is if the gui is up, and the game is paused do nothing... Well every time the gui window is up the game is paused... since the inventory gui is popup model... so take that check out and the resulting else... and move it like so...

function on_mouse_click(MouseButton button) {
Ã, // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã, //if the gui inventory is visible then run gui visible interactions
Ã, if (gInventory.Visible == true) {
Ã,  Ã, if ((button == eMouseRight) && Ã, (Mouse.Mode == eModeLookat)) {
Ã,  Ã,  Ã, mouse.Mode = eModeInteract;
Ã,  Ã,  Ã, mouse.UseModeGraphic(eModePointer);
Ã,  Ã, } Ã,  Ã, 
Ã,  Ã, else if ((button == eMouseRight) && (Mouse.Mode == eModeUseinv)) {
Ã,  Ã,  Ã, mouse.Mode = eModeLookat;
Ã,  Ã, }
Ã,  Ã, else if ((button == eMouseRight) && Ã, (Mouse.Mode == eModeInteract)) {
Ã,  Ã,  Ã, mouse.Mode = eModeLookat;
Ã,  Ã, }
Ã,  Ã, else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeInteract)) {
Ã,  Ã,  Ã, player.ActiveInventory=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
Ã,  Ã,  Ã, Mouse.Mode=eModeUseinv;
Ã,  Ã, }
Ã,  Ã, else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeLookat)) {
Ã,  Ã,  Ã, inventory[game.inv_activated].RunInteraction(mouse.Mode);
Ã,  Ã, }
Ã,  Ã, else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeUseinv)) {
Ã,  Ã,  Ã, inventory[game.inv_activated].RunInteraction(mouse.Mode);
Ã,  Ã, }
Ã, }
Ã, else if (IsGamePaused() == 1){
Ã,  Ã, //if the inventory gui is not visible, but the game is paused do nothing.
Ã, }
Ã, else { //Finally if the gui isn't visible and the game isn't paused, run normal room interation stuff
Ã,  Ã, if (button == eMouseLeft) {
Ã,  Ã,  Ã, ProcessClick(mouse.x, mouse.y, mouse.Mode );
Ã,  Ã, }
Ã,  Ã, else if (button == eMouseRight) { Ã,  // right-click, so cycle cursor
Ã,  Ã,  Ã, mouse.SelectNextMode();
Ã,  Ã, } Ã, 
Ã, }
}


So basically you just had the pause in the wrong place...


EDIT bah Ashen beat me
Either way will work, mine seems a bit more readable to me though... then again I wrote it :P
Title: Re: eMouseRight vs eMouseRightInv--Only over inventory items?
Post by: pslim on Tue 01/08/2006 22:52:28
You guys were right; it didn't work with on_mouse_click, no matter how I ordered the code.

I used on_event and got it working, though. Thanks, Alynn and Ashen. You've saved my bacon.  :)