Group variables

Lets say i have a bunch of different enemy objects and all of them should have an HP value, being able to create a group “Enemies” and creating a group-variable HP, so all objects in the “Enemies”-group will inherit this HP variable, would be really convinient.
Also when you have an object in multiple groups, it will inherit all the group variables.
This way you can organize your objects in a kind of oop way.
Another fact is: Just imagine you have 20+ objects and you realize all of them need a new variable… going through each object and adding a variable is really awkward. Also, the other way around, you realize you dont need a certain variable because you found a better solution to implement your feature, again, going through each object to delete it…, or renaming a variable…
Or just think about typos that can happen by adding a bunch of variables, what
will lead to bugs in your game that are hard to find.

2 Likes

Objects can have object variable and instance variable.

  • Object variable
    One variable shared for each objects with a default value.
    This variable can be overide by another value for specific object without change all others objects.

  • Instance variable
    a variable for specific object

You can edit Object variable in object list with right click
and you can add instance varialbe in Properties panel on scene editor.
You can see all variable in this panel.

Hello Bouh,

thanks for your reply, but i guess you did not understand what i mean.
I did not mean object or instance variables. Lets say i have an object player, an object enemy and an object doodad. All three of them are completle different object types and should behave differently. The only thing they have in common is, lets say an hp variable. So i create a group and name the group lets say objects_with_hp. And then i create a “group variable” hp and add all three of my objects to that group. Now all of them will inherit the hp variable. Now i dont have to right click all of the three objects to create an object variable hp for each of them, because they have inherited hp from the group. This is a pretty simple example, but this can and will come in handy and makes much more sense in bigger projects.

1 Like

yes yes yes this needs to happen

1 Like

my game has like hundreds of objects with same variables but different stuff so they can’t be instances and it is pain. It takes like 5-10 minutes to add the variables to each one for every variable.

1 Like

Yes I know what you mean. Can be really tedious to add variables to all the objects.

1 Like

I can see value in this idea, although I can’t speak to the complexity.

1 Like

Declare the variables with a for each group object loop. :man_shrugging:

3 Likes

The feature that @Horst is pointing to is basically what in the Construct editor is called Families.
I would use this feature for example in an point & click adventure game, where I have different interactive sprites in a scene, that would be grouped together in an object group called “hotspots”. I would then love to be able to define common variables like a “hotspotTitle” on the “hotspots” group and add common behaviors to the group instead of every single sprite. The main takeaway, though, is that I can handle the hotspots via the same general events in my event sheet. For example, I can then say something like “if mouse is over hotspot → display hotspotTitle at mouse cursor”. Right now, I would have to add that event for every sprite in my scene that I would like to be a hotspot.

This is inc

Just to clarify:

Right now you would add all of the sprites into an object group, named hotspot. You can then have one event targeting hotspot (object groups are available for any event targeting the object) and it would apply to any member of the group.
This includes variables (via events). You do not have to have an event for each sprite.

The only thing I can think of that would have to be per-sprite object would be Behaviors.