Re: mouse coordinates not giving variable values(SOLVED)

Started by geork, Wed 25/08/2010 14:31:25

Previous topic - Next topic

geork

  Hey all!
  I have some code in on_mouse_click() which goes like this:
 
Code: ags

    if(mouse.Mode == eModeWalkto  &&  AYardsWalked < 1760.0){
    XTarget = mouse.x;
    YTarget = mouse.y;
   }
   

 then I have some code in repeatedly_execute():
 
Code: ags

    if(cEgo.x == XTarget  && cEgo.y == YTarget ){
    Display("Working...");
   }

  all in GlobalScript.asc
   The problem is that the code in repeatedly_execute() never runs, meaning that mouse.x is not giving a good value to XTarget and YTarget. At first I though it had to do with the character never really reaching exactly where the mouse clicked, so  tried this instead:
 
Code: ags

    [code]
      if((cEgo.x >= XTarget - 10 && cEgo.x <= XTarget + 10) && (cEgo.y >= YTarget - 10 && cEgo.y <= YTarget + 10)){
    Display("Working...");
   }

  but still nothing, my game never displayed "Working..."
  What can I do?
   Thanks[/code]

GarageGothic

First of all, make sure that the XTarget and YTarget are actually set by putting a Display("Target: X=%d, Y=%d", XTarget, YTarget) right after your other code in the on_mouse event. Could be a lot of reasons of that not happening, e.g. your walk function claiming the click event.

Also in case you're using scrolling rooms, you need to set:

Code: ags
XTarget = mouse.x + GetViewPortX();
YTarget = mouse.y + GetViewPortY();


Because the mouse cursor uses screen coordinates and the character room coordinates.

geork

 Thanks, that worked a treat! (It was the scrolling room that caused the problem)

SMF spam blocked by CleanTalk