Really need to learn how to do this...

Ok so i have five “cubes” … it’s the same objects . Just copies .

I need to create another object for each cube and to make that object move with every single cube separately … so basically i need to create this second object once for each cube .

Now i know the create event … and do position (x,y) and that stuff .
But the problem is … it creates only for one cube … it happens only for one .

I need to create it for each cube and make it move separately from the other cubes . So when cube 1 moves the object moves for that cube or “that copy of cube” and so on .

What i tried :-
1- create event with do position “x,y” … it works but only for one cube .
2- Then i tried for each object event … still the same .
3- Tried lots of other things like pick a random object and other stuff … i don’t know . I’m pretty lost on this .
I know i’am close to the answer … been trying this a lot .

Hope someone helps . Maybe Lizard-13 … Kink
Anyway thank for helping as always .

Waiting …

You’ve to use for-each loops, yes, but it isn’t like you throw some for each loops and everything will work, it works fine for simple objects lists but you have two different object lists here, so you’ve to do a small extra step.

When you work with instances related 1-1 with other instances of different objects (text objects showing the name of each enemy, lifebars over units), always always you’ve to link the instances someway… always.

I do it with a variable “id”, for example to create the lifebars you can do it at the beginning of the scene:

For each Unit object, repeat: Conditions: No conditions Actions: Create object Lifebar Do = Unit.Variable(id) to variable "id" of Lifebar
Now each Lifebar instance has the same “id” variable than an instance of Unit, you can do it manually in the IDE too.

And with this “link” you can pick the right Lifebar each time you pick a Unit:

For each Unit object, repeat: Conditions: Variable "id" of Lifebar is = Unit.Variable(id) Actions: Do = Unit.Variable(hp)/100 to the scale X of Lifebar

There is an extension to link objects too, but it’s almost the same, just improves readability. Instead the action to set the Lifebar id = Unit id use the action to link Lifebar and Unit. And instead the condition to check if the Lifebar id is = Unit id, to pick the Lifebar, use the condition “Take into account all Lifebar linked to Unit”.
Note that you need the for-each loops anyway :wink:

Lizard-13 … I tried it but it’s not working with mine … can you make a small example on gd 5 just so I can get the idea ? … it’s my first time dealing with something like that .

For each Unit object, repeat:
what do you mean by this ?
for each object event or repeat event ?
also what is “id” … i never used it before .

i thought i was so close to answer but i geuss not :frowning:
i tried again yesterday and today but with no luck so far …
if there was a small example in gd5 about creating an object to a different “copies” of another object
That would be really great to understand what i’m doing .

Anyway . thanks for helping :frowning:
i guess i’ll leave this one for now …

It’s a for-each object event, yes.

“id” is an object variable, and you probably have used them already as it’s a common object variable, I just called it “id” :slight_smile:

Don’t surrender so easy, it isn’t so hard, you just need something to connect the objects.
Following my example of Units and Lifebars, you just need a property that each Unit shares with a single Lifebar, for example both of them have a variable “id” with the same value, or they are connected through the Link extension, or the Lifebar is the closest one to the Unit.
Then you just need to use this condition that connects them to pick the right Lifebar inside a for-each object Unit event.

:exclamation: :exclamation: :exclamation: Please read it carefully, if you do it you’ll get a clear idea of how it works:
Imagine you’ve two instances of Unit, one with variable “id” = 1 and the other with variable “id” = 2, and two Lifebar instances too, one with variable “id” = 1 and the other with “id” = 2 (you’ve to create the “id” variables manually, as you do with any object variable):

Unit object Variable "id" = 1 Unit object Variable "id" = 2 Lifebar object Variable "id" = 1 Lifebar object Variable "id" = 2
Then inside a for-each Unit loop, GD will run the events for each instance of Unit, if you do it:

For each Unit object: Conditions: No conditions Actions: Move Lifebar over Unit
The loop will run two times (because there are two Unit instances), lets assume it runs first for the Unit with “id” = 1.
First iteration, Unit with “id” = 1: What will happen?, the action to move the Lifebar over Unit will move both Lifebar objects over the Unit with “id” = 1, because GD doesn’t know which Lifebar you want to move and move all of them.
Second iteration, Unit with “id” = 2: Now GD will move all the Lifebar objects over the Unit with “id” = 2, for the same reason.

You see?, you end up moving all the Lifebar objects over the last Unit the loop ran at.
To solve it you have to grab GD, shake it a bit, and clearly say to it: I want to move the Lifebar with “id” = 1 over the Unit with “id” = 1, and move the Lifebar with “id” = 2 over the Unit with “id” = 2 !
:bulb: In other words, move each Lifebar over the Unit with the same “id” value.

So, on each Unit, we have to pick the Lifebar with the same “id” than the current Unit in the loop:

For each Unit object: Conditions: Variable "id" of Lifebar is = Unit.Variable(id) Actions: Move Lifebar over Unit
Again, the loop will run two times, but now it works this way:
First iteration, Unit with “id” = 1: The condition will pick the Lifebar instance with “id” = 1, and the action will move this Lifebar over the Unit with “id” = 1. (GD will move all the Lifebar instances with “id” = 1 actually, but you’ve only one)
Second iteration, Unit with “id” = 2: Now GD will move the Lifebar with “id” = 2 over the Unit with “id” = 2.

Note that I could just throw here a working example to show you the way, but I’m fearing people will just copy the events, try to change some values as the object names, and hope for it to work without understanding how it works. But this way is better for the users I guess.
Also it’s useful to have this text to link here and there :slight_smile:

That was so easy lol
I can’t believe it but it does feel really good when you make it happen after trying so many times you know ? :laughing:
I just did it thanks to your explanation .
Really thank you Lizard-13 .
I was really about to forget about the whole thing .

It feels really good now :smiley:

you know for me … I never copy and paste any example here in the community or anywhere . I just love to take my time to understand everything cause copy and paste will just get me through this one at this time but won’t open my mind for other things I need to create … that’s how I really learned a lot here from you guys and from the community . such an amazing place . I just love it .
so even if you did an example for this … I would still keep asking about it if there was something I didn’t understand in the codes :smiley:
That’s how I work …

Anyway … it feels amazing now that I did it . don’t care if it was this easy … but I did it thanks to your great help :slight_smile: