[SOLVED] Check if mouse mode is enabled/disabled within MouseWheelNorth

Started by arj0n, Tue 12/01/2016 21:10:47

Previous topic - Next topic

arj0n

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:
Code: ags

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


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

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:
Code: ags

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; 
      }
    }

Khris

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:
Code: ags
    if (mouse.Mode>1) mouse.Mode=mouse.Mode-1; 
    else if (player.ActiveInventory == null) mouse.Mode = eModeInteract;
    else mouse.Mode = eModeUseinv;

arj0n

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...

monkey0506

There's no built-in IsModeEnabled, but you can't switch to a disabled mode:

Code: ags
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
if (mouse.IsModeEnabled(8))
{
  // do stuff
}


Edit: See also - MousePlus module

SMF spam blocked by CleanTalk