Page MenuHomeFeedback Tracker

isNil not working in trigger condition
Closed, ResolvedPublic

Description

basically for the following code:
(!alive p2 || isNil "p2") && (!alive p3 || isNil "p3");

if in the condition field for a trigger (haven't tested it in a script), the code will never return true if either p2 or p3 is Nil {F18837}

Details

Legacy ID
995558322
Severity
Major
Resolution
Not A Bug
Reproducibility
Always
Category
Scripting
Steps To Reproduce

Bit complicated to explain..

See the repro mission it has all the triggers laid out already.

But to put it simply:

make a mission with 3 units, name these p1, p2, p3 respectively
make a trigger with the condition:

(!alive p2 || isNil "p2") && (!alive p3 || isNil "p3");

set the activation on that trigger to hint "blah blah"; or whatever
play the mission and disable one of the AI, slotting yourself in the first
kill either p2 or p3, whichever is there
observe the hint (or lack thereof)

Additional Information

See repro mission attached.

In the attached mission, all triggers seem to fire except the one titled "ultimatum", which will lose the mission when triggered.
This trigger contains the same code as in summary.

Event Timeline

Phalanx edited Steps To Reproduce. (Show Details)Apr 12 2013, 7:35 PM
Phalanx edited Additional Information. (Show Details)
Phalanx set Category to Scripting.
Phalanx set Reproducibility to Always.
Phalanx set Severity to Major.
Phalanx set Resolution to Not A Bug.
Phalanx set Legacy ID to 995558322.May 7 2016, 1:35 PM
MadDogX added a subscriber: MadDogX.May 7 2016, 1:35 PM

The problem here is that if p2 or p3 do not exist, your !alive statements are checking against undefined units. This is generally not advisable, since it can result in undefined behaviour. According to the wiki, running "alive" against a non-existing unit results in a return value of "bool": http://community.bistudio.com/wiki/alive

Phalanx added a subscriber: Phalanx.May 7 2016, 1:35 PM

I get that MadDog, but that's why the isNil is there - Fireball pointed it out to me in ticket: http://feedback.arma3.com/view.php?id=6709

*EDIT* Or is the game getting stuck on !alive and so not even checking if the unit isNil in an OR statement laid out like my example?

Xeno added a subscriber: Xeno.May 7 2016, 1:35 PM
Xeno added a comment.Apr 12 2013, 8:13 PM

Completely normal behaviour, read not a bug (thus does not belong here).

!alive undefined_variable does not return anything like it always did.

Correct is:
(isNil "p2" || {!alive p2}) && {isNil "p3" || {!alive p3}}

Note the curly braces which is lazy evaluation.
If p2 is nil it does not execute !alive p2, if p3 is nil it does not execute !alive p3.
If the first part of the statement
(isNil "p2" || {!alive p2})
is false it won't execute the second part
{isNil "p3" || {!alive p3}}

Ahh thanks Xeno.. I didn't know you would need the {}, whatever it does.. I noticed you surrounded the second argument with { }, but I tested with:
(isNil "p2" || {!alive p2}) && (isNil "p3" || {!alive p3});

and I tested with your exact code too, both work. Stuff like that confuses me!

*EDIT* Read your edits, get the explanation, very helpful thanks.

Close the ticket, guess it's not a problem after all!