Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Robster | |
Old Version | Published before Godot 3 was released. |
Hi all,
I have JSON data in a dictionary called dict
. I want to draw characters by calling the below fuction with something like drawCharacter(4)
.
func drawCharacter(id):
get_node("LabelCharacterName").set_text(dict["4"]["name"])
The problem is I can’t do the above as if I try and use id
in the string like below:
func drawCharacter(id):
get_node("LabelCharacterName").set_text(dict[id]["name"])
… it doesn’t work and returns an error that it’s an invalid index.
I can ONLY get it to work if it’s wrapped in " like in the first example.
How can I make this work? I’m currently stuck. Any help very much appreciated…
if you call it as drawCharacter(4) then the id is an integer and not a string… try replacing the 4 with “4” so it will be a string and not an integer
rustyStriker | 2017-08-24 13:29
Hey there, thanks for your answer. Unfortunately the 4
in my example was just to show what might be sent. It really needs to be whatever is in id
. Therefore it has to be a dynamically changing variable and not hard coded.
Robster | 2017-08-24 21:08