Hey all!
I have some code in on_mouse_click() which goes like this:
if(mouse.Mode == eModeWalkto && AYardsWalked < 1760.0){
XTarget = mouse.x;
YTarget = mouse.y;
}
then I have some code in repeatedly_execute():
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]
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]
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:
XTarget = mouse.x + GetViewPortX();
YTarget = mouse.y + GetViewPortY();
Because the mouse cursor uses screen coordinates and the character room coordinates.
Thanks, that worked a treat! (It was the scrolling room that caused the problem)