Access var in 2 objects in a group via their group [solved]

Lets say I have two objects in a group. They both have the variable called “Health”. That variable is different by default on both.

Lets say that in my code I would like to access the variable “Health” in both and call it by their group name - so I dont have to redo the logic for each individual object in that group.

Is it possible to do in gdevelop and how? I noticed that you can create variables for the group they are in, but obviously then they all have the same health and the same everything at the start of the frame. :frowning:

There’s probably a mistake in your events showing the content of variable. If multiple objects are taken into account by the action (for example, all the objects of the group), the result of the MyGroup.Variable(aa) will be the content of one variable aa from the first considered object. You need to use a for each loop to see every objects’ variables.

For example, two objects as Ogre and Wolf, each object with the variable Health, and a group Enemies?
I think it’s possible…

Yeah, surely a misconception, I can’t create variables for a group here :wink:
But you can set the default values of Health in each object, then you access the value as Enemies.Variable(Health), it will return the object’s health, if a Wolf fulfills the conditions, you will get the Wolf’s health (the default one in the Wolf object if it wasn’t modified), for example :slight_smile:

ahh I am so sorry. Just tried it again and works! :slight_smile:
You can alter a variable of an entire group and access it via its name.

I got confused because when you select a group of objects, the properties window shows that it has variables (0) and there is even an edit button.
I think that button should not be visible there at all when a group is selected. It made me think that groups in gdevelop dont work the way they really do.

When a group is selected (in Windows) the Properties panel shows the properties of the last selected object, and the Edition button in the ribbon is disabled :slight_smile: