Page MenuHomeFeedback Tracker

Variables declared in private statement but set to nil throw undefined variable error in scheduled space.
Assigned, WishlistPublic

Description

A variable declared in a private statement and used in a function but set to nil will throw a undefined variable error if that variable is used as the return value.

This only occurs in scheduled execution space. In non-scheduled execution space this is not an issue.

Details

Legacy ID
1357762552
Severity
None
Resolution
Open
Reproducibility
Always
Category
Scripting
Steps To Reproduce

Execute code seen in this pastebin: http://pastebin.com/BbNhJJFc

This error should not occur. Variables should be able to be set to nil after they are declared and not be removed from the variable namespace.

Additional Information

This is an annoying bug, and very hard to pin down (took me half a day to figure out that it was caused by execution in scheduled space) when encountered by developers because it occurs in valid code.

It is working CORRECTLY in non-scheduled execution! This is the incorrect method of raising this error! Assigning nil to a variable is incredibly important for any complex SQF functionality, especially in dynamic function calling where the return value may be different all the time and returning nil from an inner function is desired.

Event Timeline

Nou edited Steps To Reproduce. (Show Details)Feb 28 2014, 5:05 AM
Nou edited Additional Information. (Show Details)
Nou set Category to Scripting.
Nou set Reproducibility to Always.
Nou set Severity to None.
Nou set Resolution to Open.
Nou set Legacy ID to 1357762552.May 7 2016, 6:03 PM

Confirmed.

In the meantime, this can be used as a work-around:
if (isNil "_var") then
{

nil;

}
else
{

_var;

};

Nou added a subscriber: Nou.May 7 2016, 6:03 PM
Nou added a comment.Feb 28 2014, 8:02 AM

I just removed all but one spawn in ACRE2 haha. Everything except about 10 lines of code runs in non-scheduled events now (was pretty much already there though before this bug, scheduler space is evil).

Indeed pretty strange behaviour. Easy repro:

a = call {nil}; hint str [a]; //[any] - fine

  • spawn {a = call {nil}; hint str [a]}; //[any] - undefined variable a error

even more simple

a = nil; hint str [a]; //ok

  • spawn {a = nil; hint str [a]}//undefined a
Nou added a comment.Mar 19 2014, 11:37 AM

This bug also occurs in NON-SCHEDULED code when executed from the "action" parameter in dialog button controls!