Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: suicidal pencil on Mon 08/12/2008 22:14:33

Title: Saving mouse.x and mouse.y to a variable
Post by: suicidal pencil on Mon 08/12/2008 22:14:33
In the game I'm currently creating, when the user presses 's', their character will go into 'stealth' mode.

In stealth mode, their speed will decrease.

I already know that changing character speeds require that they are not moving. But, Instead of stopping them entirely, I want them to stop, change views, decrease speed, then continue on to where they were headed.

I've got everything down, except having the character continue on. I'm trying to save the x and y locations to two different variables, but I don't quite know how.

Here's the code, and where I'm having issues is marked by a triple asterisk (***).
What I added to existing code will be preceded by (&&&)

GlobalScript.asc


***int mouseXloc = mouse.x;
***int mouseYloc = mouse.y;
.
.
.
.
.
.
.
.

.
if (keycode==83){
    if (STEALTH_S == false){ //where STEALTH_S is a global variable
      STEALTH_S = true;
      if (player.Moving == true){
        player.StopMoving();
        SPencil.ChangeView(2);
        SPencil.SetWalkSpeed(3, 3);
        player.Walk(mouseXloc, mouseYloc, eNoBlock, eWalkableAreas);
      }
      else if (player.Moving == false){
        SPencil.ChangeView(2);
        SPencil.SetWalkSpeed(3, 3);
        }
  }
    else if (STEALTH_S == true){
      STEALTH_S = false;
            if (player.Moving == true){
        player.StopMoving();
        SPencil.ChangeView(1);
        SPencil.SetWalkSpeed(6, 6);
        player.Walk(mouseXloc, mouseYloc, eNoBlock, eWalkableAreas);
      }
      else if (player.Moving == false){
        SPencil.ChangeView(1);
        SPencil.SetWalkSpeed(6, 6);
        }
}
}
.
.
.
.
.
.
.
.

.
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    {
    }
  else if (button == eMouseLeft)
    {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
    (&&&) mouseXloc = mouse.x;
    (&&&) mouseYloc = mouse.y;
    }
  else // right-click, so cycle cursor
    {   
    mouse.SelectNextMode();
    }
  }
.
.
.
.
.
.
.

Title: Re: Saving mouse.x and mouse.y to a variable
Post by: Pumaman on Mon 08/12/2008 23:04:24
Your script looks reasonable on the face of it. What error/problem are you getting?

The only thing that sticks out is this:

***int mouseXloc = mouse.x;
***int mouseYloc = mouse.y;

You can't initialise global variables like that -- what you need to do is make sure those lines are at the top of GlobalScript.asc (ie. not inside a function), and just do this:

int mouseXloc;
int mouseYloc;

they will then get set by the code you have added to on_mouse_click.
Alternatively you could remove those lines completely and use the Global Variables editor to declare them.
Title: Re: Saving mouse.x and mouse.y to a variable
Post by: suicidal pencil on Tue 09/12/2008 00:20:30
Ah! thanks.

Works perfectly.