Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: RetroJay on Thu 28/10/2010 23:19:54

Title: Right mouse clicks within inventory. (SOLVED).
Post by: RetroJay on Thu 28/10/2010 23:19:54
Hi all good peeps.

First of all I should say that for this project I have been using 2.72. (trying to get it finished).
I have been trying to dissable right clicks, of the mouse, within the inventory GUI for some time now.

However after much reading of the manual and plowing through the help section I think I have cracked it.
I set 'Handle inventory clicks in script' to true and modified the 'on mouse click Function' to this.


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)
}
 else if (button == eMouseLeft) {
   ProcessClick(mouse.x, mouse.y, mouse.Mode );
 }
 else {   // right-click, so cycle cursor
   mouse.SelectNextMode();
}
 if (button == eMouseLeftInv) // left click on inventory item
{
 if (mouse.Mode == eModeInteract)
  {
  // select inventory item on eModeInteract:
   player.ActiveInventory = inventory[ game.inv_activated ];
 }
 else {   // run interaction if the cursor mode isn't eModeInteract:
   inventory[ game.inv_activated ].RunInteraction( mouse.Mode );
 }
}
}


It seems to work how I would like it to, at the moment.
I would like to know if anyone can see a problem with what I have done here or maybe if I could have done something different, better or neater.

I would be most grateful.
Many thanks.
Jay.
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: monkey0506 on Fri 29/10/2010 01:20:41
Based on what you have written there it seems that for both left-inventory and right (both on and off inventory) mouse clicks that it would be changing the mouse cursor..I'd suggest:

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)
  }
  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
  else if (button == eMouseRight) {   // right-click, so cycle cursor
    mouse.SelectNextMode();
  }
  if (button == eMouseLeftInv) // left click on inventory item
  {
    if (mouse.Mode == eModeInteract)
    {
      // select inventory item on eModeInteract:
     player.ActiveInventory = inventory[ game.inv_activated ];
    }
    else {   // run interaction if the cursor mode isn't eModeInteract:
      inventory[ game.inv_activated ].RunInteraction( mouse.Mode );
    }
  }
}


Other than fixing the indentation, I also changed the right-click "else" to check and verify that it actually was a right-click.
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: RetroJay on Fri 29/10/2010 02:08:08
Hi Ya Monkey.

Thank you for taking the time to look at this for me.

It works beautifully. :)
I am pleased to see that I was not totaly wrong. (just a bit wrong) ;)

Do my indentations make a difference to the script, and it's running. Or is it, as I asked, just neater?

Many thanks.
Jay.
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: Calin Leafshade on Fri 29/10/2010 02:10:26
The indents are purely for neatness in AGSScript.

However that doesnt mean you shouldnt bother with them.

Properly indented code makes it wayyyyy easier to debug so you should always indent your code.
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: RetroJay on Fri 29/10/2010 02:33:30
Hi Calin.

Thank you for the information. I will try to do this in the future. (some of my script is...messy.) ::)

I would like to ask one more question.
I have just found that the middle mouse button is still active. (not the wheel. Just the button).

How can I dissable the middle mouse button click through out my game?

Many many thanks.
Jay.
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: Ryan Timothy B on Fri 29/10/2010 02:52:37
Quote from: RetroJay on Fri 29/10/2010 02:33:30
How can I dissable the middle mouse button click through out my game?
Monkey fixes it and explains it with his code.

Quote from: monkey_05_06 on Fri 29/10/2010 01:20:41
Other than fixing the indentation, I also changed the right-click "else" to check and verify that it actually was a right-click.


You have:

[...]
 else if (button == eMouseLeft) {
   ProcessClick(mouse.x, mouse.y, mouse.Mode );
 }
 else {   // right-click, so cycle cursor
   mouse.SelectNextMode();
 }
[...]


The else would imply that if button clicked ISN'T the left click, it would run the mouse.SelectNextMode();. That means with this script, if you middle click or right click it will run the next mode action.


Which is why Monkey changed it to:

 [...]
 else if (button == eMouseLeft) {
   ProcessClick(mouse.x, mouse.y, mouse.Mode );
 }
 else if (button == eMouseRight) {   // right-click, so cycle cursor
   mouse.SelectNextMode();
 }
 [...]
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: RetroJay on Fri 29/10/2010 03:58:18
Hi Ryan.

Thank you for your reply but you have misunderstood what I am saying.

I have used Monkey's script and it works fine, within the inventory window.

The 'middle mouse button' and also the 'right button' still works on the GUI buttons for 'opening inv', 'Save', 'Load' and 'Quit'.

I am simply looking for some help with these. Could I modify what I already have to do this?

Thanks.
Jay.

Edit-
I thought I should explain more. I do not want 'Right' or 'Middle' mouse clicks to open the Inventory, Save or Load GUI's.
Here is the script for the inventory button.


function btnIconInv_Click(GUIControl *control, MouseButton button) {
 
  gui[1].Visible = false;
  show_inventory_window();
}


If I can get this to work then the other buttons should be no problem.

Once again. Thank you for your help.
Jay.
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: monkey0506 on Fri 29/10/2010 04:34:37
Just add an "if (button == eMouseLeft)" in that function and you'll be good to go. Be sure to use braces if you want to include both of those statements conditionally.
Title: Re: Right mouse clicks within inventory. Not sure if I have done it right. Right.
Post by: RetroJay on Fri 29/10/2010 05:25:33
Hi Monkey.

Thank you.
I really appreciate your help.

That's fantastic.

Cheers.
Jay.