alleycat 28 Posted January 25, 2016 Trying to use mapclick and calculate a distance, but the script gives errors: finished = 0; hint "Click on map to move #players marker."; _posplayer = getpos player; openmap true; onMapSingleClick "player setpos _pos; onMapSingleClick ''; true"; onMapSingleClick """strat_players"" setmarkerpos _pos; player setpos _pos; finished = 1; onMapSingleClick ''; diag_log text format [""Distance from start to end: %1"", _posplayer distance _pos]; true"; waitUntil {(finished == 1)}; hint "#players marker moved to click position."; hint format ["Distance from start to end: %1", _posplayer distance _pos]; Error message: 19:57:23 Distance from start to end: scalar 19:57:23 Error in expression < start to end: %1", _posplayer distance _pos]; if (true) then { };> 19:57:23 Error position: <_pos]; if (true) then { };> 19:57:23 Error Undefined variable in expression: _pos Share this post Link to post Share on other sites
f2k sel 164 Posted January 25, 2016 _pos only exists within the onMapSingleClick finished = false; hint "Click on map to move #players marker."; _posplayer = getpos player; //openmap true; while {alive player or visibleMap} do { onMapSingleClick "player setpos _pos; onMapSingleClick ''; true"; onMapSingleClick " 'strat_players' setmarkerpos _pos; player setpos _pos;global_pos=_pos; finished = true; onMapSingleClick ''; diag_log text format ['Distance from start to end: %1', _posplayer distance global_pos]; true"; waitUntil {finished}; sleep 0.1; finished = false; hint "#players marker moved to click position."; hint format ["Distance from start to end: %1", _posplayer distance global_pos]; }; I added a while to make it work more than once, I'm not sure it's what your after but at least it works. global_pos = _pos to get around the variable issue. 1 Share this post Link to post Share on other sites
alleycat 28 Posted January 25, 2016 How did I not see that before? Thanks. Also global_pos is a global variable even when it is declared within something? Share this post Link to post Share on other sites
hoverguy 177 Posted January 25, 2016 Also global_pos is a global variable even when it is declared within something? Yes it is. Share this post Link to post Share on other sites