Object groups - how do they work?

i dont understand this part of the code very well

this is of a tempalte i bought called RTS

heres the thing: shouldnt the part where it says “change the variable takingdamage of ALLBUILDINGS to true” make it so ALL the buildings in that group take damage? how is the code separating the specific building from the other ones?

so i guess what im saying is that i dont understand events with groups of objects

Are those events subevents of a for each object?

yes, they are, but, i still dont understand

If it’s a sub event of a for each object then only 1 object gets picked at a time. So, only 1 object is used for the conditions, expressions and actions.

Events use pick lists. By default all actions and conditions use all of the objects or instances. Conditions and other events like for each object reduce the pick list. As long as all of the conditions are true then any action will be use the current pick list. The pick list gets reset at the start of each new event but continues to be used for all sub events.

1 Like

It is confusing
BUT if you think about it
It kinda makes sense

Group references portion of objects so ones inside that group
While for each do to them different stuff based on how their conditions are meet
Cause it is checking linked objects

https://wiki.gdevelop.io/gdevelop5/events/foreach/#when-to-use-it

So to my understanding just because there is take into acc all linked objects

You NEED for each there

SO it do not do all that crap to one building but to all of them

I would assume most stupid explanation is
If you make action to change opacity of your object set to
255 / Object.Variable(MaxHP) * Object.Variable(HP)
Which would make your object lose opacity as its lose HP var
Then without for each it would change it either for one or for all to value of first one
With for each event it would do it individually to each object based on their own object var

So for each is what filters here to which object execute actions in what way based on how condition meets their current state individually

Where object group is just filter on what kind of objects you want to work

Like imagine you have class and that is your group of objects while single classmate is single object
(This is your object group)

And they all want to get into night club
(This is your action)

But there is bouncer at the enters who checks IDs and tell GTFO to every classmate below 16
(This is your for each)

Without for each here bouncer would kick whole class or only one kind

Where with for each it filters each classmate individually based on their age
(Age would be object variable)

1 Like

sorry for answering the both of you so late, there were complications but you have been of great help

thank you

2 Likes

“For each” is not relevant here. This condition is what matters: “The X position of AllBuildings < Soldier.CenterX()”"

That condition picks all the objects in AllBuildings whose X position is less than the other object.CenterX(). Whether you are going through each AllBuilding individually or all at once, the same objects will be picked.

For each object by itself will still operate on all the objects if no other conditions are given. I suspect that the previous event was For each instance of Soldier rather than Building, just a guess though

Also dang, this does not look like a robust template at all. Using Wait actions that can so easily break… impossible to maintain groups… hardcoded values… ew.

1 Like