Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid use of nil comparison #7402

Closed
KHunter-Arma opened this issue Jan 5, 2020 · 5 comments
Closed

Invalid use of nil comparison #7402

KHunter-Arma opened this issue Jan 5, 2020 · 5 comments
Assignees
Labels
Milestone

Comments

@KHunter-Arma
Copy link

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

FILTER(_loaded,_x != nil);

I believe it should be

FILTER(_loaded,!isNil "_x");

@commy2
Copy link
Contributor

commy2 commented Jan 5, 2020

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

@commy2 commy2 self-assigned this Jan 5, 2020
@KHunter-Arma
Copy link
Author

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 <ach _loaded;

_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.

@commy2
Copy link
Contributor

commy2 commented Jan 5, 2020

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

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

instead.

@jonpas jonpas added this to the 3.13.1 milestone Jan 5, 2020
@dedmen
Copy link
Contributor

dedmen commented Jan 5, 2020

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

@PabstMirror
Copy link
Contributor

_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" = []

@commy2 commy2 closed this as completed Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants