Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Tue 12/01/2016 21:10:47

Title: [SOLVED] Check if mouse mode is enabled/disabled within MouseWheelNorth
Post by: arj0n on Tue 12/01/2016 21:10:47
I use the following mouse modes:

mode 1 = look
mode 2 = interact
mode 3 = talk
custom mode 8 = inventory


For mouse mode 8: when selecting an inv item, this mode get a certain Graphic set en gets enabled:

  mouse.EnableMode (eModeInventory);
  mouse.ChangeModeGraphic(eModeInventory, 39);
  mouse.Mode = eModeInventory;


After using this item on an object or char, this mouse mode gets disabled.

mouse.DisableMode(eModeInventory);


In the global script, for the MouseWheelNorth, I'd like to check if mouse mode 8 is enabled/disabled, and set the mouse to mode 8 if 8=enabled or to mode 3 if 8=disabled.
But I can't figure out how to do that.

Here's the global script part:

else if (button == eMouseWheelNorth) {
    // Mouse-wheel up, cycle cursors
    // If mode isn't LOOK, set the previous mode
    if (mouse.Mode>1) mouse.Mode=mouse.Mode-1;
    else 
    {
      // ...but if it is LOOK mode...
      if (mouse.Mode 8 == enabled) // <<THIS (PSEUDO) LINE IS MY PROBLEM, I HAVE NO IDEA HOW TO CHECK IF A MOUSE MODE IS ENABLED/DISABLED
      {
        //...and mouse mode 8 is enabled, set mouse mode to 8.
        mouse.Mode=8;
      }
      else
      {
        // If they don't, however, just set it to mode TALK
        mouse.Mode=3;
      }
    }
Title: Re: Check if mouse mode is enabled/disabled within MouseWheelNorth in GlobScript
Post by: Khris on Tue 12/01/2016 21:53:43
The short answer is, you can't.
There's no IsModeEnabled().

You could use a bool variable and simply keep track of the whether the mode is enabled yourself, then check that variable.
However, if you set player.ActiveInventory to null after the item was used, AGS will move to the next mode (since you can't have eModeUseinv active and at the same time have no player.ActiveInventory, which also means you don't need to disable it).

So you can simply use that to check whether the mode is active:
    if (mouse.Mode>1) mouse.Mode=mouse.Mode-1;
    else if (player.ActiveInventory == null) mouse.Mode = eModeInteract;
    else mouse.Mode = eModeUseinv;
Title: [SOLVED] Check if mouse mode is enabled/disabled within MouseWheelNorth
Post by: arj0n on Tue 12/01/2016 22:14:16
Yes, I know there's no IsModeEnabled(), that was just a pseudo line.
I was really hoping there was a quick work-around instead of having to use player.ActiveInventory == null.
Because using that means I need to go through all the rooms and set it to null where an item is used.
A bool is indeed an option but the player.ActiveInv will do fine.
If I only had thought of this from the start. *slaps forehead*

Thanx for the answer, Khris!

EDIT:
Also, I wasn't using inventory items, I only used custom mouse mode 8 and set a certain (inv) graphic to it.
Bad choice I guess...
Title: Re: [SOLVED] Check if mouse mode is enabled/disabled within MouseWheelNorth
Post by: monkey0506 on Tue 12/01/2016 23:02:32
There's no built-in IsModeEnabled, but you can't switch to a disabled mode:

Code (ags) Select
bool IsModeEnabled(this Mouse*, CursorMode mode)
{
  CursorMode oldMode = this.Mode;
  this.Mode = mode;
  bool result = (this.Mode == mode);
  this.Mode = oldMode;
  return result;
}


Usage:

Code (ags) Select
if (mouse.IsModeEnabled(8))
{
  // do stuff
}


Edit: See also - MousePlus module (http://www.adventuregamestudio.co.uk/forums/index.php?topic=43434.msg577719#msg577719)