Last active
September 10, 2023 17:05
-
-
Save tabularelf/f97f92bc96fa6c172d8186172be8403f to your computer and use it in GitHub Desktop.
array_to_struct and struct_to_array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function array_to_struct(_array) { | |
var _struct = {}; | |
var _i = 0; | |
repeat(array_length(_array)) { | |
if (is_array(_array[_i]) || is_struct(_array[_i])) { | |
show_error("Cannot convert array or struct to key", true); | |
} | |
_struct[$ string(_array[_i])] = _array[_i]; | |
++_i; | |
} | |
return _struct; | |
} | |
function struct_to_array(_struct) { | |
var _names = variable_struct_get_names(_struct); | |
var _len = array_length(_names); | |
var _array = array_create(_len); | |
var _i = 0; | |
repeat(_len) { | |
_array[_i] = _struct[$ _names[_i]]; | |
++_i; | |
} | |
return _array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment