Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Fri 29/03/2019 10:45:21

Title: How do I move when my mouse cursor mode is not eModeWalkTo?
Post by: bx83 on Fri 29/03/2019 10:45:21
Basically I have a system where:
-the mouse has a walk to/look at/interact with/talk to cursors
-you change cursor using the mouse wheel or tapping the left mouse button

When you, ie. have the lookat icon, whatever object or character the mouse is over, the mouse cursor will change to activated ("eyes open" for lookat)
When it's not, it's "eyes closed".

But when you click on an area where there is just blank space (walkable area != 0), then I want it to walk there.

So...

......
    else if (mouse.Mode == eModeLookat)                              // LOOKAT
    {
      newGraphic = 105;                                         // eye close
      Hotspot* hs = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
      Object* ob = Object.GetAtScreenXY(mouse.x, mouse.y);
      Character* ch = Character.GetAtScreenXY(mouse.x, mouse.y);
      InventoryItem* inve = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

      if (gInventory.Visible == true && inve != null)
      {
        if (inve.IsInteractionAvailable(eModeLookat))
        {
          newGraphic = 2056;                                    // eye open
        }
      } else {
        if (lt == eLocationHotspot)
        {
          if (hs != hotspot[0])
          {
            if (hs.GetProperty("hidden") == false)
            {
              if(hs.IsInteractionAvailable(eModeLookat))
              {
                newGraphic = 2056;                              // eye open
              }
            }
          }
        }
        else if (lt == eLocationCharacter)
        {
          if (ch != null)
          {
            if (ch.IsInteractionAvailable(eModeLookat))
            {
              newGraphic = 2056;                                 // eye open
            }
          }
        }
        else if (lt == eLocationObject && ob.IsInteractionAvailable(eModeLookat) && ob.Visible == true)
        {
          newGraphic = 2056;                                    // eye open
        }
       
        else if (GetWalkableAreaAt(mouse.x, mouse.y)!=0) {          //NONE OF THIS WORKS
          if (mouse.Click(eMouseLeft)) {    //walking          //NONE OF THIS WORKS
            ProcessClick(mouse.x, mouse.y, eModeWalkto);          //NONE OF THIS WORKS
          }
        }
       
      }
    }
    else if (mouse.Mode==eModeInteract)                              // INTERACTION
.....


Basically I want to say, "when the player clicks left mouse button in a space that's a walkable area only and is not a null walkable area (walkable area 0), I want them to walk there, regardless of what type of icon it is".
If someone has the eModeLookAt, and they're on an object - look at the object.
Otherwise, walk there.
Simple, but not simple.

What am I doing wrong?
Title: Re: How do I move when my mouse cursor mode is not eModeWalkTo?
Post by: Cassiebsg on Fri 29/03/2019 12:50:26
Can't you just end with else and tell it to walk?
Title: Re: How do I move when my mouse cursor mode is not eModeWalkTo?
Post by: bx83 on Fri 29/03/2019 17:39:05
Yes, but how to walk on mouse click?
I don't know how to get it to process a click or check for left mouse button, and I don't know how to make it go there when I click (as opposed to constantly following the mouse cursor and walking all the time).
Title: Re: How do I move when my mouse cursor mode is not eModeWalkTo?
Post by: Cassiebsg on Fri 29/03/2019 18:35:46
I need to check the manual or one of my games.

But it's something like Room.ProcessClick(mouse.x, mouse.y, eModeWalk);
Title: Re: How do I move when my mouse cursor mode is not eModeWalkTo?
Post by: Crimson Wizard on Fri 29/03/2019 18:59:29
Quote from: bx83 on Fri 29/03/2019 17:39:05
Yes, but how to walk on mouse click?
I don't know how to get it to process a click or check for left mouse button, and I don't know how to make it go there when I click (as opposed to constantly following the mouse cursor and walking all the time).

Is the code you posted above from repeatedly execute or on_mouse_click? I can't tell... It seem to be changing mouse graphic and not start any interaction, so I assume rep_exec.

You are using Mouse.Click function wrong. It does not tell you when the mouse is clicked, it does the click.
https://www.adventuregamestudio.co.uk/manual/ags66.htm#Mouse.Click

If you want to do something on mouse click event, this is what on_mouse_click function is for. It already takes clicked button as parameter which you may refer to.

Crude example
Code (ags) Select

function on_mouse_click (MouseButton button)
{
    if (button == eMouseLeft)
    {
         if (GetLocationType(mouse.x, mouse.y) == eLocationNothing &&
             GetWalkableAreaAt(mouse.x, mouse.y) != 0)
         {
               Room.ProcessClick(mouse.x, mouse.y, eModeWalk);
         }
    }
}