Ace3: Invalid use of nil comparison

Created on 5 Jan 2020  路  5Comments  路  Source: acemod/ACE3

Hello guys, sorry for not conforming to reporting standards, but this one is strictly code-related. Isn't this invalid code?

https://github.com/acemod/ACE3/blob/62fccd6ff03b77803dc4a811ffda89e27c8bd3c9/addons/cargo/functions/fnc_removeCargoItem.sqf#L56

I believe it should be

FILTER(_loaded,!isNil "_x");

kinbug

Most helpful comment

_loaded select {nil} returns empty array

so before PR this would cause loss of loaded items

q setVariable ["ace_cargo_loaded", ["ACE_Wheel", "ACE_Wheel"]];
["ACE_Wheel", q, 1] call ace_cargo_fnc_removeCargoItem
q getVariable "ace_cargo_loaded" = []

All 5 comments

Did you encounter an actual issue or did you review the existing code?

Well under normal circumstances, I haven't encountered any issues. However, if you try something like this:

["ACE_Wheel", _vehicle, 10] call ace_cargo_fnc_removeCargoItem;

when there aren't 10 tyres in the cargo, which is pretty bad, I admit, you end up getting this:

2020/01/05, 14:42:27 Error in expression

_loaded = _loaded select {_x != nil};
true
};

if (!_continue) exi>
2020/01/05, 14:42:27 Error position: <_x != nil};
true
};

if (!_continue) exi>
2020/01/05, 14:42:27 Error Undefined variable in expression: _x
2020/01/05, 14:42:27 File z\ace\addons\cargo\functions\fnc_removeCargoItem.sqf..., line 56

I just happened to gaze at the code and saw this and thought it might have been a mistake, that's all. If it's intentionally made that way, my bad.

Only if you call this function is scheduled environment.
Try:

isNil {
    ["ACE_Wheel", _vehicle, 10] call ace_cargo_fnc_removeCargoItem;
};

instead.

Yes _x != nil is invalid. != will just return nil, always, even if _x is not nil.
@654wak654

_loaded select {nil} returns empty array

so before PR this would cause loss of loaded items

q setVariable ["ace_cargo_loaded", ["ACE_Wheel", "ACE_Wheel"]];
["ACE_Wheel", q, 1] call ace_cargo_fnc_removeCargoItem
q getVariable "ace_cargo_loaded" = []
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Snak3Doc picture Snak3Doc  路  4Comments

GalNa picture GalNa  路  3Comments

thirald picture thirald  路  3Comments

BlueNexus picture BlueNexus  路  3Comments

SimichRE picture SimichRE  路  3Comments