• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

global parent object variables

D

Darth Binary 1010

Guest
I've heard it's a good idea to create a parent object for everything with a list of general variables. If you use this strategy, can you list all the variables you have in the parent?
 
T

Taddio

Guest
Parents are for all the common code share. Ex: changing sprite when changing direction would apply to NPCs as well as player, so you could have an object par_character that has this behavior, and make obj_npc and obj_player children of that.
Good for menu buttons, enemy AI, making a "solid" family for collisions, all sorts of things.
Press F1 while in GM and check the magic unfold for how to use it properly!
Note that all chidren will have all the variables of the parent, unless you override the create event, but then you would have to be extra careful as tto what you do next.
You can always override an event, and you can inherit in code with event_inherited();

You would then define the variables specific to each instances.
Ex: par_enemy would have dmg=0; in create

And in obj_some_enemy create you could go:
event_inherited();
dmg = SOME_CREATURE_DMG;
 

NightFrost

Member
Now that's a broad question. I use some parenting when it makes sense, but the variables depend entirely on use of said objects, so it is impossible to generalize. For example, for enemy-type parent objects I usually declare a full range of base variables and their state machine enumerator. Variables for specialized actions go into child objects that require them (like fly speed). In my settings control system, the parent setting object has some base data like which global variable is being controlled, but only the slider child object has variables for slider sprites and slider length because it is the only one that needs them.
 
Top