Repeat for two diffrent Object Instances

“enemy 1” is moving, the object" HitBoxMB", should have always the same position, in this case, always in front of enemy1…this should be for every instances of the object “enemy 1” and “HitBoxMB”. Here is the way, i made it :

…it works…
but i’m pretty sure there is an smater way to make it work… the problem here is…if there would be a third Enemy (“enemy 1” id=3), i have to copy paste , and adapt the stats for the third enemy…so if i need e.g. 50, i have to do it 50 times…I tried it with “repeat for each instance of …” but it i couldnt make it work…e.g all instances of “HitBoxMB” set to the exact same position…

i tried it in a lot of diffrent ways the last week :confused:
i’m appreciating every help:)
greetings :muscle:

P.s.: If you have a headline, which fits better, I’ll change the headline^^

For each Enemy1
Trigger once ][ Create object hitbox / Change id of hitbox: set to Enemy1.Variable(id) / change z order

For each Enemy1
id of Enemy1 = hitbox.Variable(id) ][ change position

You are very right, when there’s copypasting, there’s usually a more clever way. :slight_smile:

1 Like

thanks for ur answer :slight_smile:

(The way u discribed)
i don’t know why it doesnt work…do you see a mistake, I can’t see?
…The “hitbox” is only at one position… Maybe all of them are at the same spot. i think they all are at position of “id of Enemy = 1”.
I’m sure there is an obvious mistake, but I overlooked a lot of times…

Did you first give each Enemy1 an id variable? :slight_smile:
Otherwise, they all have id=0, and it can’t work.

Next to the preview button, there is the debugger button.
Open the debugger preview to check the value of your global, scene and instance variables, it will help you understand what’s going on. :blush:

Hmm not in the events… only at properties for every “Enemy1” at the scene:

Ah i didnt know this function from the debugger preview… i will try to check it…
(I made e new game, for testing only this…specific problem…The events from the game are very short.)
I’m not sure but as far as i can see from the debugger Preview…there is
Enemy1: id=1,id=2,id=3, same with “hitbox”…but here the position is exactly the same…
as mentioned I’m using the debugger preview the first time that way, I’m not sure…
@Gruk Thanks for your help so far!

I think we should focus on the hitbox instead, so the second one should be for each hitbox.
And if that doesn’t work, try to invert likeso: the id of hitbox equals Enemy1.Variable(id)
And if that doesn’t work, you can still use the Link actions, that’s what I did :smile:

1 Like

you were right!

I tried both :wink: :

both are working!:heart_eyes::clap: thanks :pray:

i never tried working with link actions…
out of curiosity could you explain(or share a link), where I could need them or their benefits?
I read the documentation to understand the basics…Really appreciating the GDevelop documentations, thanks to authors :pray:

Cool :+1:

The id variable technique offers some benefits due to its variable and integer (number) nature. e.g a condition “id is less than 50”.
The Link technique offers the “unlink” options. Changing the id variable of an object to unlink it would be quite dirty, so if you need to unlink, go for link. :crazy_face:

1 Like

Ahh i think understand it better now :see_no_evil: thanks! :raised_hands:t5::grin:

1 Like