How to change variables in an object for the variables in a Resource

Godot Version

4.5

Question

I want to make a boon picking menu like in ahdes or any other rougelike, and I made 6 Items with a recourse, and then stored them all in another resource to make an Array of them.

now I want a button to choose one of this resources form the array at random and showcase its descrption image and everything, but I don't know for the life of me how to change the labels and sprites I have in the buttons for those inside the Resources, I'm compelatly new to this, I don't know what I'm doing most of the time, and i've been trapped with this for more than a week now

here’s the script inside the button, in the right is the array resource that has the other items taht are resources as well, each of them with their description, anmes and image palce holdres

here is the item resource example

ant his is the button, pretty simple, I just want this to work so I can move on to the next part that is actually making the button do what the item is supposed to once you click it

I feel this is simple, and I’m jsut missing the key to keep moving foward, but as i said, im pretty new to this

To solve big problems we usually break them down into smaller problems until we get to things we know how to do.

Do you know how to set the text of a label in script?

Do you know how to read properties from a resource in script?

1 Like

yeah, i’v done it before in little tests, thats why i dont understand why it returns as null or says it doesnt exist,or just dones’t do anything

Where’s the code that sets the label’s text property from the resource?

Thats exatly what i want to do

i know tahat if i just want to cahnge it i can grab the resource and say

lable.text = resource.description

because I alredy have that resource properties filled

but I dont know how to do it when the resource in inside another resource that is an array, I have no idea, there’s no code of that because i dont know how to do it

here’s the example of waht i did taht of course doesn’t work, I think is because the random item that is picking doesn’t know the resource properties that is inside the array?

and the “pick boon” func i put it inside the array

is just a simple “pick_random()”

so it knows to pick random from insdide that array resource?

otherway it just thell me pick random doesnt exist
im lost

So when you pick random, you’re getting the reference to a resource. What fields are defined in that resource?

this ones, and there are 6 diferent items with this propetries

after taht I made another resourse called boonInv and made it an array that has this 6 things inside

and then I added taht resource to a button so the button can pick at random any of them

but the script to make the button do taht is where i’ve been stuck for like a week and a half

What does your BoonInv script look like? Are you getting any error messages?

not much really, just created the array resource, and put the “pick random” func there because when i put it inside the button script it tells me it deson’t exist

The same way you access node.property, you can access deep resources the same way. So, it’s something like resource_array[0].nested_resource.nested_resource.property depending on what the properties of your resources are named.

Calling pick_random() doesn’t do anything on its own. You need to return its result if you want to receive it from calling pick_boon():

func pick_boon():
	return Boons.pick_random()

just by having this make it work? ot what else am i missing?, this is inside BoonsInv resource, the Array that hast he item resources

I don’t get how to structure the code… i feel f** useless

so, if the BoonsInv is the ARRAY and it is inside the code in the var: Boons

and that array has the items, and the items have a property called “description”, how should i get it?

label.text = Boons.???

if I rawdogit and write
Boons[0].??? something else
it tells me it spects a “STRING” instead of an int inside the [ ]

im so lost, whenever I think im getting closer i realise, i’m in the same place

Just run the code and see if it works. Even if it doesn’t, you might get some error message to share.

BoonInv is not the array, it’s a resource that contains the array. Without using the pick_boon() function, the path from the button should be Boons.Boons.pick_random() to get one of the resources from that array.

you are a freakinag genius and i love u, I hope you win all your deadlock matches form here to eternity

now I jsut have to figure out how to get it so 2 of the same are not picked,
THANKS!!!