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

fix script error when calling undefined events #378

Merged
merged 1 commit into from
Jun 14, 2016

Conversation

commy2
Copy link
Contributor

@commy2 commy2 commented Jun 13, 2016

After #375 we copy the arrays from the event namespace. This leads to a typical SQF facepalm inducing issue...

["undefined", 1] call CBA_fnc_localEvent

22:35:17 Error in expression <) then {        _params call _x;    };} forEach +(cba_events_eventNamespace getV>
22:35:17   Error position: <forEach +(cba_events_eventNamespace getV>
22:35:17   Error foreach: Type Number,Not a Number, expected Array
22:35:17 File x\cba\addons\events\fnc_localEvent.sqf, line 7
22:35:17 Error in expression <) then {        _params call _x;    };} forEach +(cba_events_eventNamespace getV>
22:35:17   Error position: <forEach +(cba_events_eventNamespace getV>
22:35:17   Error Generic error in expression
22:35:17 File x\cba\addons\events\fnc_localEvent.sqf, line 7

If the variable on the namespace was undefined, it would previously do:
CODE forEach (LOCATION getVariable STRING)
CODE forEach nil
nil

Since we are now using the + operator to copy the array, it goes:
CODE forEach +(LOCATION getVariable STRING)
CODE forEach +nil
CODE forEach nil*
->ERROR

nil* is a special nil tagged as number instead of the "neutral" nil from the getVariable operator. This is probably because + is expected to return . The default syntax for plus is obviously for adding numbers and that's what the internals assume when nil is used as argument.
forEach expects an array on the right side. In unscheduled environment, the command will fail silently for the "neutral nil", but for the "number type nil" (nil*), the input will be detected as being the wrong type. Therefore it reports:
Error foreach: Type Number, [...], expected Array

I'll call these concepts "number flavoured" and "neutral flavoured" nil-types from now on. Thanks.

param saves the day again.

@commy2 commy2 added the Bug Fix label Jun 13, 2016
@commy2 commy2 added this to the 2.4.2 milestone Jun 13, 2016
@PabstMirror
Copy link
Contributor

👍 Tested working good

@commy2
Copy link
Contributor Author

commy2 commented Jun 13, 2016

fun

str [locationNull getVariable ""]
-> "[<null>]" // neutral nil

str [+(locationNull getVariable "")]
-> "[scalar NaN]" // NUMBER type nil

str [nil joinString ""]
-> "[string]" // STRING

str [getUnitLoadout nil]
-> "[array]"

str [displayParent nil]
-> "[01894A9C]" // DISPLAY type nil

str [nil displayCtrl nil]
-> "[01894ABC]" // CONTROL type nil

str [nil controlsGroupCtrl nil]
-> "[01894ABC]" // also CONTROL, therefor same hex thingy

str [if nil]
-> "[018EADFC]"

str [nil]
-> "[any]" // ???

@Killswitch00 Killswitch00 merged commit b5da4cc into master Jun 14, 2016
@Tenga
Copy link

Tenga commented Jun 16, 2016

Just as an FYI, this nil behavior was documented here a while back.

@thojkooi thojkooi deleted the fix_calling_undefined_events branch June 16, 2016 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants