Saving mouse.x and mouse.y to a variable

Started by suicidal pencil, Mon 08/12/2008 22:14:33

Previous topic - Next topic

suicidal pencil

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
Code: ags


***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();
    }
  }
.
.
.
.
.
.
.


Pumaman

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.

suicidal pencil


SMF spam blocked by CleanTalk