Well, when setting mapPic.position, change it to this. This is purely because it annoys the stuff out of me how you did it.
mapPic.position = $finposx SPC $finposy2;
Also, purely because it looks ugly the way you also make numbers negative, I will do this.
$posx2 = ($posx / 2.7) - ($posx / 2.7) - ($posx / 2.7);
$posy2 = ($posy / 2.7) - ($posy / 2.7) - ($posy / 2.7);
Instead of redefining $deposy and $deposx in each statement, simply move them to the top of the script instead of in the functions. They aren't local and it doesn't seem as if they change. Also, remove the quotes. Integers are not strings like that. Instead of "-550" you use -550 . Also, you should change pretty much everything except $deposx and $deposy to local variables because defining them globally doesn't make too much sense. You should also add a
return %finposx;
To the end of each XPos and YPos function (changing the finpos variable respectively). You should also change
XPos(%pos);
YPos(%pos);
to
%x = XPos(%pos);
%y = YPos(%pos);
and use %x and %y in place of the global variables $finposx and $finposy2 you used to use.
I'm just going to rewrite most of the stuff that you should. A lot of it is nitpicking at things that I cannot stand. Some of the code is capitalized differently, and so is spacing. It doesn't really matter as long as it looks fine to you.
function refresh()
{
%camera = serverConnection.getControlObject();
%pos = %camera.getPosition();
%x = XPos(%pos); // Use returned values for the variables we want
%y = YPos(%pos);
mapPic.position = %x SPC %y; // Much cleaner now, isn't it?
schedule(200,0,'refresh'); // I think a function should be a tagged string, and since you also don't need an argument I removed that.
}
function XPos(%pos)
{
%posx = getWord(%pos,0); // Using local instead of global...
%posx2 = (%posx / 2.7) - (%posx / 2.7) - (%posx / 2.7); // Longer but it makes more sense to me.
%finposx = %posx2 + $deposx;
return %finposx;
}
function YPos(%pos)
{
%posy = getWord(%pos,1);
%posy2 = (%posy / 2.7) - (%posy / 2.7) - (%posy / 2.7);
%finposy = %posy2 + %deposy;
return %finposy;
}
I'd also like to say pretty much all of this is purely optional but makes more sense to me and looks better in most cases.
The problem was also in the YPos function you used the variable %ypos instead of %pos (used in the function)