Associate objects

Hello all,
I have 2 objects
men
hat

Each second a man is created and moved randomically. (maximun 30 sprites)
The problem is: I would create a hat for each men and the hat have to stay on the head of each men (position of hat = position of man).
But it is necessary associate to each man with his hat. How can I realize it ?

Thanks,
J

Hello J,

Just an idea as I am not very skilled in GD… But, when creating a Man why don’t you give the man a unique ID as an internal object variable. Then when creating a hat, specify an ID_Man as an object variable in the hat. Then, when binding Hat coordinates to Man corrdinates, add a condition that Man.Id = Hat.Id_Man ?

In theory looks feasible but I let you discover in practice whether it works or not…

Good luck.

Alexandre

1 Like

You can probably use the Link actions too, but I’m not very experienced with these.

1 Like

create one “global variable (men)”, and one “object variable (men)” for object men, and one “object variable (hat)” for object hat !
,
Every-times a man is created, if his object variable (men) is equal to 0 , so you add 1 to “global variable (men)”, and set this global variable to object variables of men and hat !

After, you do if “object variable (hat)” is equal to “object variable (men)”, put hat to the men position !!!

Thanks a lot !!!
I resolved with these code:
I create the Hat using this code
image
and on each frame:

Thanks,
J

2 Likes