Page MenuHomeFeedback Tracker

BIS_fnc_getFromPairs is unable to return nil when key cannot be found
New, WishlistPublic

Description

When calling BIS_fnc_getFromPairs from a scheduled environment and the provided key cannot be found, the following error is recorded:

Error in expression < _pairs;

if (isNil "_value") exitWith {_default};

_value}>

  Error position: <_default};

_value}>

Error Undefined variable in expression: _default

File A3\functions_f\Arrays\fn_getFromPairs.sqf, line 63

Details

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

This one throws an error:
[[],"LALA"] spawn BIS_fnc_getFromPairs;

This one does not:
[[],"LALA"] call BIS_fnc_getFromPairs;

Additional Information

The reason seems to be that you cannot reference a variable that has been set to nil in a scheduled environment. For example the following will throw an error:

  • spawn {_a = nil;_a};

Error in expression <[] spawn {_a = nil;_a};>

  Error position: <_a};>
  Error Undefined variable in expression: _a

Doing the same thing using "call", works:

  • call {_a = nil;_a}

Changing line 63 from BIS_fnc_getFromPairs from
if (isNil "_value") exitWith {_default};
to
if (isNil "_value") exitWith {if (isNil "_default") then {nil} else {_default}};
works around the issue.

Event Timeline

Gundy edited Steps To Reproduce. (Show Details)Sep 7 2014, 2:49 AM
Gundy edited Additional Information. (Show Details)
Gundy set Category to Scripting.
Gundy set Reproducibility to Always.
Gundy set Severity to None.
Gundy set Resolution to Open.
Gundy set Legacy ID to 1033237928.May 7 2016, 7:23 PM
Bohemia added a subscriber: Gundy.Sep 7 2014, 2:49 AM
Gundy added a comment.Dec 7 2014, 11:00 AM

Is this going to get looked at? Its still "new".

FYI, I have seen other BIS functions incorporate the same workaround / fix (check return value for nil before returning it).
I think getting this to behave the same in both scheduled and un-scheduled environments would be preferred, ideally so that one can return a nil variable without having to check for it, but I'd take it the other way around if this means we get some consistency here.