Skip to content

Instantly share code, notes, and snippets.

@jackmakesthings
Created September 24, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmakesthings/765adba3bcecaede76bf to your computer and use it in GitHub Desktop.
Save jackmakesthings/765adba3bcecaede76bf to your computer and use it in GitHub Desktop.
Godot currently has a bug that prevents altering dictionaries made via json_parse; this is one user's workaround. Might come in handy considering I'm using json as my godot project's data format.
# Workaround proposed by Hammer Bro again :
const DICTIONARY_TYPE = typeof({})
# Recreate the structure of a dictionary, maintaining references to all leaf-level values.
func copy_dictionary(dictionary):
var output = {}
for key in dictionary.keys():
var value = dictionary[key]
if typeof(value) == DICTIONARY_TYPE:
output[key] = copy_dictionary(value)
else:
output[key] = value
return output
# So that in previous code, one need to call :
json_dictionary.parse_json('{"outer_key" : {"inner_key" : "value"}}')
json_dictionary = copy_dictionary(json_dictionary)
# Basically, this workaround copies the content of the dictionary obtained by parse_json() into a new dictionary structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment