Jump to content
Sign in to follow this  

undefined variable in expression-help

Recommended Posts

Hoping someone can help.

I have been looking at and trying out various ways for a hunt script for a mission I am making, "behind enemy lines"- I 'm sure by the title you can understand why I want a script like this !

I have something that works really well in itself- but I can keep getting errors : "undefined variable in expression" which is just annoying and although the script works, I try not to have errors. Specifically, it's saying line 9 _chaser/_marker is undefined. This script includes a kind of debug which shows the waypoints/markers of the "hunter" group (just a way of testing it's working). You name the group, both hunter and hunted e.g. chaser1 = group this and hunted = group this. Then call from trigger whatever: null = [groupnameofhunter, groupnameofhunted, chaserposaccuracy, debug, refreshrate] execVM "chase.sqf

e.g. null = [chaser1,hunted, 50, 0, 20] execVM "chased.sqf";

This is the script:

private ["_chaser", "_chased", "_radius", "_debug", "_refresh","_pospos","_marker"];
_chaser = (_this select 0);
_chased = (_this select 1);
_radius = (_this select 2);
_debug = (_this select 3);
_refresh = (_this select 4);

while {true}
do { 
_chaser addWaypoint [getPos leader _chased, _radius, 1];
_chaser setCurrentWaypoint [_chaser, 1];
if (_debug > 0) then { 
Marker = createVehicle ["PointerLarge_ACR", position leader _chased, [], 0, "FLY"];
_pospos = getpos (leader _chaser);
//deletemarker _marker;
_marker = createmarker [_nazwa, [0,0]];
_marker setmarkerpos _pospos;
_marker setmarkershape "ICON";
_marker setmarkertype "Flag";
_marker setmarkercolor "ColorRed";
_marker setmarkersize [1,1];
_marker setmarkertext _nazwa;
hint "Tracking..."; 
else {
sleep _refresh;
//deleteVehicle Marker;
deleteWaypoint [_chaser, 1];


Is there a way of stopping the "undefined variable in expression" error, without having to rewrite the whole script !?

Any help would be great. Thanks

Share this post

Link to post
Share on other sites

Works fine for me. I copy and pasted your script, didn't change anything. Placed an OPFOR group named chaser1, and a BLUFOR group named hunted. Started the mission, and called the script with the same line you used.

OPFOR proceeded to move to BLUFOR's location. With debug on, the markers don't show up, but otherwise it seems to work fine.

Since you're getting an undefined variable message, maybe you have a typo in one of the group leaders init line?

Share this post

Link to post
Share on other sites

Thanks for checking Shpook, appreciated. I double, double checked and no typo's in naming groups. It's strange you're not getting script errors- mine doesn't shut up! I think it's because I haven't defined _chaser or _marker in my script- thought private would do it. I'm pretty new/novice to scripting tbh. I am hoping someone has some code that can define the errors. I seem to remember reading somewhere (I can't find it now, tried searching) that there is a way to do that? my variable true or something (?) and various other ways ?

Edited by pathfinder2-1

Share this post

Link to post
Share on other sites

No problem. In your case, private isn't honestly doing much unless you call the script from another script. It still allows variable sharing with inner scopes(I think). Also, _chaser is defined here:

 _chaser = (_this select 0);

While _marker is defined here:

_marker = createmarker [_nazwa, [0,0]];

I generally use hints and/or log reporting on a step by step basis when I run into trouble. So just start with:

hint format["%1", _chaser];

and see if it's defined, then move down the line.

You can also combine them into one hint:

hint format["%1, %2, %3", _chaser, _chased, _radius];

Do it for each variable, but only put up one hint at a time. Make sure they return the values they should. But honestly, I didn't get a single error with your code. :)

Share this post

Link to post
Share on other sites

Thanks Shpook, you've been a great help.

You're right it is defined, I just thought there was a mistake somewhere. It's strange though, as sometimes it shows no errors at all and at other times it does- always _chaser and sometimes _marker- weird. Perhaps I should double check through all my groups and make sure there are no typos, etc (there are quite a number of groups tbh, a fairly "big" mission), as that could be what is causing the occasional error. The hint is really useful, thanks a lot for that.

I will have another look tomorrow- tired now :) Cheers.

Share this post

Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
Sign in to follow this