Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Puppetsj on Mon 03/11/2008 07:25:01

Title: Want character to follow the mouse cursor.... (solved)
Post by: Puppetsj on Mon 03/11/2008 07:25:01
See subject. I put the code on Interact as I want it to be kind of like dragging the character around.

The code:
{
cBall.TurnBeforeWalking = false;
while (Mouse.IsButtonDown(eMouseLeft)) {
  if (cBall.y <= 115) {
cBall.StopMoving();
  }
  else if (cBall.y >= 125) {
cBall.StopMoving();
  }
  else {
cBall.Walk(160,  mouse.y, eAnywhere);
  }
}
}


Of course the game crashes:

QuoteError: run_text_script1: error -6 running function 'cBall_Interact':
Error: Script appears to be hung (150001 while loop iterations without an update) in "GlobalScript.asc", line 426

Also the mouse cursor won't move when the key is pressed, and the character doesn't move until after I let go of the
Title: Re: Want character to follow the mouse cursor, only when the left MB is pressed...
Post by: monkey0506 on Mon 03/11/2008 07:39:27
Instead of putting the script in the interaction function, try repeatedly_execute_always:

// rep_ex_always
  if (mouse.IsButtonDown(eMouseLeft)) {
    if ((cBall.y <= 115) || (cBall.y >= 125)) cBall.StopMoving();
    else cBall.Walk(160, mouse.y, eAnywhere);
  }


Just leave the cBall.TurnBeforeWalking line in the interaction function.
Title: Re: Want character to follow the mouse cursor, only when the left MB is pressed...
Post by: Puppetsj on Mon 03/11/2008 08:02:05
It works now, kind of. Still doesn't move until after I release the mouse button, and then only to the spot where I let go.
Maybe what I'm trying is impossible, but I doubt it after seeing all of the things people have managed to squeeze out of this engine. Most likely just a tad bit more complex than I feel it should be.
Title: Re: Want character to follow the mouse cursor, only when the left MB is pressed...
Post by: monkey0506 on Mon 03/11/2008 08:06:41
Wow...I'm sorry I was kind of distracted. You're telling the Character to walk every single game loop. Try adding a check that the character is not already moving:

// rep_ex_always
  if (mouse.IsButtonDown(eMouseLeft)) {
    if ((cBall.y <= 115) || (cBall.y >= 125)) cBall.StopMoving();
    else if (!cBall.Moving) cBall.Walk(160, mouse.y, eAnywhere);
  }


Edit: I should really think about what I'm doing here....