-
Notifications
You must be signed in to change notification settings - Fork 148
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
addKeybind - Handle empty strings to indicated no code #688
Conversation
Shouldn't this automatically be done by |
addons/keybinding/fnc_addKeybind.sqf
Outdated
@@ -88,6 +88,10 @@ if (_defaultKeybind isEqualTypeParams [0, false, false, false]) then { | |||
_defaultKeybind = [_defaultKey, [_defaultShift, _defaultControl, _defaultAlt]]; | |||
}; | |||
|
|||
// Handle empty strings to indicated no code | |||
if (_downCode isEqualType "") then {_downCode = {};}; | |||
if (_upCode isEqualType "") then {_upCode = {};}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not go the extra mile and do:
+if (_downCode isEqualType "") then {
_downCode = compile _downCode;
};
+if (_upCode isEqualType "") then {
_upCode = compile _upCode;
};
Would make more sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new method is consistent with the old way which only checked if it was a string
if(IS_CODE(_downCode)) then {
[_hashDown, "keydown"] call cba_fnc_removeKeyHandler;
Compiling could cause problems if they pass something like "#nothing"
.
I figured it's deprecated anyway as there is no reason to not pass {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know what you mean, but then this isn't limited to STRING either, but any type.
And "#nothing"
is a bad example, because that actually doesn't throw an error when compiling or calling the result, because #
is treated like #LINE 1
and other instructions that survive preprocessing even though it does nothing.
@jonpas True, but it also throws an error. From what I understand, STRING used to work as replacement for CODE just like how you can use STRING inside |
Ah, you are correct indeed, totally forgot about the error. |
addons/keybinding/fnc_addKeybind.sqf
Outdated
@@ -88,6 +88,10 @@ if (_defaultKeybind isEqualTypeParams [0, false, false, false]) then { | |||
_defaultKeybind = [_defaultKey, [_defaultShift, _defaultControl, _defaultAlt]]; | |||
}; | |||
|
|||
// Handle empty strings to indicated no code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines below results in any string, empty or not, to be regarded as an empty code block The comment suggests otherwise.
_downCode - Code for down event, empty string for no code. <CODE>
ACRE uses this:
["ACRE2", "CycleRadio", (localize LSTRING(CycleRadio)), { [1] call FUNC(cycleRadios) }, "", [58, [true, false, true]]] call cba_fnc_addKeybind;