Skip to content

Commit

Permalink
possible fix for #1358
Browse files Browse the repository at this point in the history
  • Loading branch information
jokoho48 committed Oct 14, 2020
1 parent 79c04b6 commit 937e9b2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions addons/hashes/fnc_hashCreate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Description:
Parameters:
_array - Array of key-value pairs to create Hash from [Array, defaults to []]
_defaultValue - Default value. Used when key doesn't exist. A key is also removed from the hash if the value is set to this default [Any, defaults to nil]
_clearOnDefault - Setting default value behaves like a remove
Returns:
Newly created Hash [Hash]
Expand All @@ -31,10 +32,10 @@ Author:
SCRIPT(hashCreate);

// -----------------------------------------------------------------------------
params [["_array", [], [[]]], "_defaultValue"];
params [["_array", [], [[]]], "_defaultValue", ["_clearOnDefault", true]];

private _keys = _array apply {_x select 0};
private _values = _array apply {_x select 1};

// Return.
[TYPE_HASH, _keys, _values, if (isNil "_defaultValue") then {nil} else {_defaultValue}];
[TYPE_HASH, _keys, _values, if (isNil "_defaultValue") then {nil} else {_defaultValue}, _clearOnDefault];
2 changes: 1 addition & 1 deletion addons/hashes/fnc_hashSet.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private _default = _hash select HASH_DEFAULT_VALUE;
if (isNil "_default") then {
_isDefault = isNil "_value";
} else {
if (!isNil "_value") then {
if (!isNil "_value" && {_hash param [HASH_CLEARONDEFAULT, true]}) then {
_isDefault = _value isEqualTo _default;
};
};
Expand Down
2 changes: 1 addition & 1 deletion addons/hashes/fnc_isHash.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ SCRIPT(isHash);
// -----------------------------------------------------------------------------
params ["_hash"];

_hash isEqualType [] && {count _hash == 4} && {(_hash select HASH_ID) isEqualTo TYPE_HASH}
_hash isEqualType [] && {count _hash == 5} && {(_hash select HASH_ID) isEqualTo TYPE_HASH}
1 change: 1 addition & 0 deletions addons/hashes/script_hashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define HASH_KEYS 1
#define HASH_VALUES 2
#define HASH_DEFAULT_VALUE 3
#define HASH_CLEARONDEFAULT 4

#define TYPE_HASH "#CBA_HASH#"

0 comments on commit 937e9b2

Please sign in to comment.