Could i create a var defined by a sprite a label and a script?

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

Greets!

Meaning i’m working on inventory and items, and i’d need their ID to be called and loaded at convenance.

What do you mean by “defined by a sprite a label and a script”? What do you want your variable to contain? And what exactly is stopping from setting it up that way?

njamster | 2020-02-25 16:06

Erh… What’s stopping me? My knowledge… :s

I want to get access to those items with a single word, that’ll get their sprite/image, their label/description, and their script/stats. If possible eh.

Syl | 2020-02-25 16:24

:bust_in_silhouette: Reply From: Magso

I want to get access to those items with a single word

That is what a dictionary allows you to do.

var newDictionary = {"Image": Image, "Description": String, "Script stats": [int, float, string]}

#Examples of retrieving dictionary keys
print(newDictionary["Description"])
    
var script_stats_array = newDictionary["Script stats"]
print(script_stats_array[3])

Thxs, but how to insert and get the sprite of the image?

Syl | 2020-02-25 17:46

I gave examples of different types, are you wanting the image or the sprite node?

for the image

var newDictionary = {"Image": load("res://path/to/theImage.jpg"), ...

for the sprite node I would play it safe using get_node first.

var sprite_node = get_node("path/to/node")
var newDictionary = {"Image": sprite_node, ...

Magso | 2020-02-25 17:53

Cheers! I’ll tinker with that.

Syl | 2020-02-25 18:08