How to retrieve an "int" value from a dictionnary ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rensae

For something like const MONSTER: { "shadow": { "sprite: "res://[insert file path], "hp": 20, "atk": 15 }, }

And I want to retrieve it on another script, how can I do it ?

I know that, to retrive a picture, you can assign a variable with, for exemple :
var monster = $"[node path].get_monster("monster_name")"
with a function
func get_monster(monster_id): if monster_id in MONSTER: return MONSTER[monster_id] else: return null

Then you can just load it with load(monster.sprite)

It’ll be used to get a monster in the dictionnary, and when it’s chosen it’ll apply those values in his stats. But I can’t figure it out, it keeps saying me that it’s not possible in a “Dictionnary”

Hope there is enough info on it

:bust_in_silhouette: Reply From: jtarallo

Hi,

var monster_id = "SHADOW"
var shadow = MONSTER[monster_id]

print(str(shadow["hp"]))
print(str(shadow["atk"]))

var hp = int(shadow["hp"])
var atk = int(shadow["atk"])

#do whatever you want with hp and atk vars

Thanks a lot ! :3

Rensae | 2020-06-09 19:06

No problem! Good luck!

jtarallo | 2020-06-09 19:08