Group variables


#1

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

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.


#3

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.