Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: JoanMon on Mon 24/01/2022 21:09:01

Title: [SOLVED] Double click to run?
Post by: JoanMon on Mon 24/01/2022 21:09:01
Hi, I'm trying to make my character run with double click.
- AGS Editor .NET (Build 3.5.1.11)
- Bass Template
- Module: DoubleClick_1.0.0

I use this command line, but does not work correctly.
Any suggestions as to what I am doing wrong? Thanks.

In Global Script:
Code (ags) Select
function on_mouse_click(MouseButton button)
{
  if (DoubleClick.Event[eMouseLeft]) {
    // double-click code
    player.SetWalkSpeed(50, 50);
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode );
    }
    else
    {       
    player.SetWalkSpeed(50, 50);
    }
  if (eMouseLeft) {
    // single-click code
    player.SetWalkSpeed(15, 15);
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode );
    }
    else
    {
    player.SetWalkSpeed(15, 15);
    }
}


Title: Re: Double click to run?
Post by: Pax Animo on Mon 24/01/2022 21:20:48
I've had similar problems with this and also using the "Bass Template", though I'm not using the Module: DoubleClick_1.0.0

My issue has been, (player can not change speed whilst moving.)

I wonder if that's linked to your issue.

The tumbleweed template, seems to handle this issue correctly, though I've only used it once.
Title: Re: Double click to run?
Post by: Khris on Mon 24/01/2022 21:25:37
Try this:
Code (ags) Select
function on_mouse_click(MouseButton button) {
  if (button != eMouseLeft) return;
  ClaimEvent();
  int speed = 15;
  if (DoubleClick.Event[eMouseLeft]) speed = 50;
  player.StopMoving();
  player.SetWalkSpeed(speed, speed);
  Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
}
Title: Re: Double click to run?
Post by: JoanMon on Mon 24/01/2022 21:43:07
Thanks Khris, but it does not work "ClaimEvent:No event to claim"

Edited:
I've removed "ClaimEvent"
I've added another "player.StopMoving();"
Inside the room works correctly, but when changing the room the character doesn't stop, it continues walking.
I solved it by adding "player.StopMoving();" in "room_AfterFadeIn", it works, but I don't know if it's the right way to do it.

Code (ags) Select
  if (button != eMouseLeft) return;
  int speed = 15;
  player.StopMoving();
  if (DoubleClick.Event[eMouseLeft]) speed = 50;
  player.StopMoving();
  player.SetWalkSpeed(speed, speed);
  Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
Title: Re: Double click to run?
Post by: Khris on Mon 24/01/2022 22:51:03
Where did you put this?

Anyway, you're using the BASS template so the following should work:
1. open the TwoClickHandler Script
2. find line 154, it says  Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
3. directly above that line, insert this:
Code (ags) Select
      if (button != eMouseLeft) return;
      int speed = 4;
      if (DoubleClick.Event[eMouseLeft]) speed = 2;
      player.StopMoving();
      player.AnimationSpeed = speed;


Note that changing the animation speed (actually a delay, hence: lower value -> faster walking) is the proper way to speed up walking; this will prevent the player from gliding / moon-walking (provided that the movement speed properly corresponds to the walk cycle frames)
Title: Re: Double click to run?
Post by: JoanMon on Mon 24/01/2022 23:18:29
QuoteWhere did you put this?
In Global Script

The new code, works correctly.
Thank you very much, Khris.
Solved.