Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Construed on Fri 13/12/2013 00:06:34

Title: Stop player walking to look icon(Solved)
Post by: Construed on Fri 13/12/2013 00:06:34
Hey, I disabled the automatically move to hotspots "In look mode" in the general game settings but it still walks wherever i click, anyone know whats up with it?
Title: Re: Stop player walking to look icon
Post by: monkey0506 on Fri 13/12/2013 05:21:29
What does your on_mouse_click function look like? That setting only relates to how ProcessClick(x, y, eModeLookat) is handled by the engine. We'd need to see your full code to be sure you're not just calling player.Walk yourself. :P
Title: Re: Stop player walking to look icon
Post by: Construed on Fri 13/12/2013 13:01:39
Ah, I see what your saying,

Code (ags) Select

function on_mouse_click(MouseButton button){

   if (button == eMouseLeft)
   CafeDo(String.Format("walks to %d %d", mouse.x, mouse.y));
   SierraFunctions.mouse_click(button);

}
Title: Re: Stop player walking to look icon
Post by: monkey0506 on Fri 13/12/2013 13:20:35
Hmm... (wtf)

Could you post the definitions of the CafeDo and SierraFunctions.mouse_click functions? I think the latter is from a module Dualnames wrote, but I can't be bothered right now to hunt it down and download it.

I also want to point out that:

Code (ags) Select
   if (button == eMouseLeft)
   CafeDo(String.Format("walks to %d %d", mouse.x, mouse.y));
   SierraFunctions.mouse_click(button);


Is the same as:

Code (ags) Select
   if (button == eMouseLeft)
   {
      CafeDo(String.Format("walks to %d %d", mouse.x, mouse.y));
   }
   SierraFunctions.mouse_click(button);


The way you have it written doesn't make that readily clear. Probably not the issue here, but I wanted to ensure that's what you meant to do (and if so, suggest you fix your formatting/indentation).
Title: Re: Stop player walking to look icon
Post by: Construed on Fri 13/12/2013 14:35:08
Code (ags) Select

/*
General:
Sierra Style Control Method, means there's no hotspot label to indicate hotspots,
you right-click to go through modes and left-click to process a click. As for inventory
well, you open it using a pop-up bar, and you can either examine, or select an item.
*/
static function SierraFunctions::InvLook() {
mouse.Mode=eModeLookat;
}
static function SierraFunctions::InvSelect() {
mouse.Mode=eModeInteract;
mouse.UseModeGraphic(eModePointer);
}
static function SierraFunctions::InvClose(GUI*invenory) {
invenory.Visible=false;
mouse.UseDefaultGraphic(); 
}
static function SierraFunctions::mouse_click(MouseButton buton) {//handle//false
if (buton==eMouseLeft) {


if (mouse.Mode==eModeWalkto) {
player.Walk(mouse.x, mouse.y, eNoBlock, eWalkableAreas);
}
else {
ProcessClick(mouse.x, mouse.y, mouse.Mode);
}
}
if (buton==eMouseRight) {
mouse.SelectNextMode();
Wait(5);
}



That is the sierra control code, I doubt the CafeDo is the problem because its just speaking to the server, but let me know if this code doesn't explain the problem and i'll upload it anyway.
Thanks for the help!
Title: Re: Stop player walking to look icon
Post by: Khris on Fri 13/12/2013 15:00:54
It's right there in lines 22-24.
Actually no, let me take another look.

Edit: what's with the missing ts?

Construed, just to clarify: the character walks when you click a hotspot with the look cursor, right?
Title: Re: Stop player walking to look icon
Post by: Construed on Fri 13/12/2013 15:26:36
No, He  walks anytime i click the look icon anywhere.
I commented out the server code and it seemed to work but lost the ability to switch modes with right click for some strange reason and the server code is quite necissary so I'm thinking perhaps i can add some code like

Code (ags) Select

if (mouse.Mode == eModeWalkto)
{
   // code here
}


To the server code:

Code (ags) Select

void CafeDo(String action)
{
  IRCAction(channel, action);
  player.Act(action);
     
}

void Act(this Character *, String action)
{
    if (action.Length < 1)
      return;
   
    String msg[] = action.IRCSplit();
    if ((msg[0] == "walks") && (msg[1] == "to"))
    {
      if (this.Room == player.Room)
        this.Walk(msg[2].AsInt, msg[3].AsInt, eNoBlock);
      else
      {
        this.x = msg[2].AsInt;
        this.y = msg[3].AsInt;
      }
    }
    else if ((msg[0] == "is") && (msg[1] == "at"))
    {
      if (!this.Moving)
      {
        this.x = msg[2].AsInt;
        this.y = msg[3].AsInt;
      }
    }
    else if ((msg[0] == "looks") && (msg[1] == "like"))
    {
      this.ChangeView(msg[2].AsInt);
    }
   
        else if ((msg[0] == "speed") && (msg[1] == "is"))
    {
     
      this.StopMoving();
      this.SetWalkSpeed(msg[2].AsInt, msg[3].AsInt);

    }   
           
            else if ((msg[0] == "tele") && (msg[1] == "is"))
    {
      this.ChangeRoom(msg[2].AsInt, msg[3].AsInt,169);
    }

         
   
}



Title: Re: Stop player walking to look icon
Post by: Construed on Fri 13/12/2013 15:40:09
I think i fixed it by editing the code as such:

Code (ags) Select

function on_mouse_click(MouseButton button){

   if ((button == eMouseLeft) && (mouse.Mode == eModeWalkto))
   CafeDo(String.Format("walks to %d %d", mouse.x, mouse.y));
   SierraFunctions.mouse_click(button);

}


Everything seems to be working fine now, thanks for leading me in the right direction guys!
Title: Re: Stop player walking to look icon(Solved)
Post by: monkey0506 on Fri 13/12/2013 20:20:24
Right, the problem was, in fact, the CafeDo method:

Code (ags) Select
function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeft) // player clicked left mouse
  {
    CafeDo(String.Format("walks to %d %d", mouse.x, mouse.y)); // REGARDLESS OF MODE, call CafeDo("walks to X Y")
  }
  // ...
}

void CafeDo(String action) // called with action = "walks to X Y"
{
  // ...
  player.Act(action); // calls player.Act("walks to X Y")
}

void Act(this Character*, String action) // this = player, action = "walks to X Y"
{
  String msg[] = action.IRCSplit(); // msg[0] = "walks", msg[1] = "to", msg[2] = "X", msg[3] = "Y"
  if ((msg[0] == "walks") && (msg[1] == "to"))
  {
    if (this.Room == player.Room) // this == player
    {
      this.Walk(msg[2].AsInt, msg[3].AsInt, eNoBlock); // calls player.Walk(X, Y, eNoBlock)
    }
    // ...
  }
  // ...
}


If you can manage to follow the logical flow of the program, your on_mouse_click function was calling CafeDo with a "walks to" action regardless of the mouse/cursor mode. That was your problem. ;)
Title: Re: Stop player walking to look icon(Solved)
Post by: Construed on Fri 13/12/2013 21:22:15
Well said, If only I had your commenting earlier I'd have avoided a long term bug i recently fixed where i was trying to use player. instead of this. to effect in-game code.
Title: Re: Stop player walking to look icon(Solved)
Post by: monkey0506 on Sat 14/12/2013 00:26:04
Well there doesn't seem to be a mismatch in this particular case. You should use player if you want to only refer to the player, and use this inside an extender method when you want to refer to the Character calling the method (e.g., cEgo for cEgo.Act and cDave for cDave.Act).
Title: Re: Stop player walking to look icon(Solved)
Post by: Construed on Sat 14/12/2013 14:48:08
Ah, I see! Thank you for the clarity :D