#trying to pass a resource to a child and getting this error

1 messages · Page 1 of 1 (latest)

cunning shale
#

so im having my battle scene contain 4 resources for potential enemies
those enemies are specified from an array, and for every one that exists, it creates an enemy child node, and then needs to apply the enemy resource from the array to it

#

battle contains enemy_group which needs to duplicate enemy based on how many enemies are in the initial array

#

the child runs this on _ready()

rough blaze
#

If you're coming from other programming languages, for i in array is equivalent to a "for each" loop rather than a standard for.

i in this case is already a Resource, so you can either do instance.resource = i, or change the loop to for i in enemies.size().

cunning shale
#

thats a bit weird

#

thankyou sir 🫡

#

i will see if it works

rough blaze
#

No problem.

cunning shale
#

it kinda does

#

i think it's just the enemy not loading its texture

#

$Sprite2D.texture = TEXTURE

#

i have this

#

it doesnt load tho

#

wait i just forgot to specify it xd

#

thankyou

#

can the child see its own ID?

rough blaze
#

Which ID do you mean, sorry?

#

The position in the array, or the actual ID that Godot assigns each node?

cunning shale
#

the position in the array

rough blaze
#

No. The only ways to know are either to iterate using an integer so that you can use it again later, (i.e. save the i from for i in enemies.size()) or to search for it inside the array later (var i = enemies.find(enemy)). But if you do hold onto the original position in the array, that will get out of date if you ever delete anything from earlier in the array, so finding it when you need it is the safest way.

cunning shale
#

thats gonna be a bit tricky

#

i was going to have enemies attack in order of index

#

i guess i could have entities attack when a var reaches their ID, and it skips enemies that no longer exist?

rough blaze
#

The easiest way is probably to have something external telling them to attack. The enemy group for example could call i.attack() on each one in turn.

cunning shale
#

position = Vector2(0, index * 32)
i cant do this for some reason

#

ah

#

cuz it gives the resource allocation not the iteration number

#

forgot immediately

#

im cnofused on how to put for i in enemies.size() into a var

#

oh wait

#

sorry

#

im silly

#

instance.index = enemies.size()
nvm this sets it to the total size and not the current index