gRowlxd 10 Posted April 15, 2017 So I have this script that loops itself every 10th sec, which checks if 2 objects are alive, and if it destroyed. It will launch a script. The objects are called _fobnato & _fobaaf and the script is: Spoiler if (!alive _fobaaf) then {execVM fobdeleteaaf.sqf}; if (!alive _fobnato) then {execVM fobdeletenato.sqf}; // Waits 10 seconds and then loops script sleep 10; execVM "scripts\locked\FOB\fobdelete.sqf"; When I join it gives me an errror "Undefined variable in expression" Any ideas? Share this post Link to post Share on other sites
Larrow 2820 Posted April 15, 2017 {execVM "fobdeleteaaf.sqf"} No quotes around your script paths. _fobaaf addEventHandler[ "Killed", { hint "AAF FOB supply box destroyed"; execVM "fobdeleteaaf.sqf"; } ]; Share this post Link to post Share on other sites
killzone_kid 1330 Posted April 15, 2017 if (!isNil "_fobaaf" && {!alive _fobaaf}) then {execVM fobdeleteaaf.sqf};if (!isNil "_fobnato" && {!alive _fobnato}) then {execVM fobdeletenato.sqf}; Share this post Link to post Share on other sites
pierremgi 4850 Posted April 15, 2017 Just verify your local variables are define somewhere, prior to the loop, and mind the scopes. As you said, your in a loop... which one? the script itself? So, no chance your local variables will be defined one day. You could wait for a long time without any execution of your sqfs. A simple solution could be global variables for your objects. Share this post Link to post Share on other sites
gRowlxd 10 Posted April 15, 2017 1 hour ago, killzone_kid said: if (!isNil "_fobaaf" && {!alive _fobaaf}) then {execVM fobdeleteaaf.sqf};if (!isNil "_fobnato" && {!alive _fobnato}) then {execVM fobdeletenato.sqf}; It doesn't give me the error, but it doesn't run the fobdelete scripts Share this post Link to post Share on other sites
gRowlxd 10 Posted April 15, 2017 1 hour ago, Larrow said: {execVM "fobdeleteaaf.sqf"} No quotes around your script paths. _fobaaf addEventHandler[ "Killed", { hint "AAF FOB supply box destroyed"; execVM "fobdeleteaaf.sqf"; } ]; What do you mean with that script you showed me, what would that do and where should I put it / execute it. Share this post Link to post Share on other sites
pierremgi 4850 Posted April 15, 2017 17 minutes ago, gRowlxd said: What do you mean with that script you showed me, what would that do and where should I put it / execute it. in the same script you defined _fobaaf as a local variable. You can place that anywhere after, and forget your looping script. Share this post Link to post Share on other sites
gRowlxd 10 Posted April 15, 2017 1 minute ago, pierremgi said: in the same script you defined _fobaaf as a local variable. You can place that anywhere after, and forget your looping script. So how does this work if it doesnt loop? Share this post Link to post Share on other sites
pierremgi 4850 Posted April 15, 2017 An event handler is "waiting" for an event (your object "killed", fully damaged here). Then, It fires the code inside. Share this post Link to post Share on other sites
OMEGABLEU 3 Posted April 23 On 4/15/2017 at 8:39 AM, killzone_kid said: if (!isNil "_fobaaf" && {!alive _fobaaf}) then {execVM fobdeleteaaf.sqf};if (!isNil "_fobnato" && {!alive _fobnato}) then {execVM fobdeletenato.sqf}; Why the curly braces around the !alive part of the clause? I have a similar statement in a HitPart eventhandler that throws an "Undefined variable in expression" error if the _target was hit by a falling inanimate object (no shooter I guess). Is this because of the missing braces? Even though I am testing for the condition that there is no shooter. if(not(isNil "_shooter" || isNull _shooter)) then { lorea doTarget _shooter; lorea fireAtTarget [_shooter, handgunWeapon lorea]; }; Share this post Link to post Share on other sites
Larrow 2820 Posted April 23 12 minutes ago, OMEGABLEU said: Why the curly braces around the !alive part of the clause? Lazy evaluation, part in curly braces is only done if the previous statement is true/satisfies the overall statement. 12 minutes ago, OMEGABLEU said: (no shooter I guess). Is this because of the missing braces? not(isNil "_shooter" || isNull _shooter) Yes, if _shooter isNil then isNull _shooter makes no sense. If isNull _shooter is in braces then isNil returns true which satisfies the OR statement so isNull will never be evaluated. 2 Share this post Link to post Share on other sites
OMEGABLEU 3 Posted April 23 5 minutes ago, Larrow said: Lazy evaluation, part in curly braces is only done if the previous statement is true. Yes, if _shooter isNil then isNull _shooter makes no sense. Ok thank you! I was not aware. I've change the line to match KK's example if(!isNil "_shooter" && {!isNull _shooter}) then { lorea doTarget _shooter; lorea fireAtTarget [_shooter, handgunWeapon lorea]; }; Share this post Link to post Share on other sites