Saving Variables of Parent object that are differenet on each object

S

Stratos.la

Guest
Say oEnemyParent has a global variable of spd , dmg , hp and together with the player when he levels up the enemies also gain more power, hp etc. The saving system for the player is completed but im having trouble storing the enemy variables. To my understanding if i add the variables of the enemy to the save function how can it load each and every different enemy saved variables? as it is now i have one parent element and all my enemies inherited from that except that i change hp and spd on "tougher" enemies. If i save one global. enemy variable how can it work and follow each and every enemy's difference??
 

samspade

Member
Say oEnemyParent has a global variable of spd , dmg , hp and together with the player when he levels up the enemies also gain more power, hp etc. The saving system for the player is completed but im having trouble storing the enemy variables. To my understanding if i add the variables of the enemy to the save function how can it load each and every different enemy saved variables? as it is now i have one parent element and all my enemies inherited from that except that i change hp and spd on "tougher" enemies. If i save one global. enemy variable how can it work and follow each and every enemy's difference??
I'm not sure I fully understand your leveling up system, but it sounds like your enemies scale as a function/result of the player's level. If this is strict enough, you wouldn't need to save anything other than the player's level and then do the calculation.
 
S

Stratos.la

Guest
I'm not sure I fully understand your leveling up system, but it sounds like your enemies scale as a function/result of the player's level. If this is strict enough, you wouldn't need to save anything other than the player's level and then do the calculation.
yes i have set it up like so
GML:
global.p_exp += 10
if (global.p_exp > global.p_exptolevel)
{
with (oEnemyParent) {en_hp_max += round(en_hp_max * upg);}
global.p_level +=1;
global.p_exp = 0;
global.p_exptolevel = 70 * global.p_level
global.skp += 2;
global.skp_next = 2 * global.p_level;
global.hp = global.hp_max;
global.mp = global.mp_max;
}

alarm[0] = room_speed * 3;
but as you see all my variables are global ( i might not need them global to be sure im testing that now) and if i add in the save system the en_hp variable it gets stores globaly for all my enemies but i dont know how to tell the game that enemy 1 has 10hp enemy 2 has 20 etc etc. i am trying to make all of them grow with one single variable on one parent object. Can you further explain what you said please?
 
S

Stratos.la

Guest
just thought id bump it today to see if anyone has any idea! thank you again!
 

samspade

Member
I must not be thinking well, but I don't see where you use any of the player level variables to calculate the enemy hp and so on or where you use those variables to set an individual enemy's hp.

But to put what I mean in a different way if enemy hp is base_hp * player level, then you don't need to save anything other than the player's level because you can always calculate the correct enemy hp with their base hp (which wouldn't change) and the saved player's level. There are probably an infinite number of ways to do this particular thing, but one way would be to put the following in the player's create event:
GML:
///enemy create event

hp = base_hp * global.player_level;
You could also put this in a function, or a method, or set it with every instance create, and so on.
 
S

Stratos.la

Guest
GML:
global.p_exp += 10
if (global.p_exp > global.p_exptolevel)
{
with (oEnemyParent) {en_hp_max += round(en_hp_max * upg);}
this part is executed in a persistent object that gives the player xp over time when in battles. and it allocates a percentage every time the player gets a level.
 

Nidoking

Member
{en_hp_max += round(en_hp_max * upg);}
I don't see you changing upg here. You can perform this step however many times based on the player's level, or just do en_hp_max *= power(1 + upg, global.p_level)

That will compound the rounding error, but you could compensate for that in the game by maintaining the unrounded version separately and rounding into the variable that you use to make the numbers match.
 

samspade

Member
GML:
global.p_exp += 10
if (global.p_exp > global.p_exptolevel)
{
with (oEnemyParent) {en_hp_max += round(en_hp_max * upg);}
this part is executed in a persistent object that gives the player xp over time when in battles. and it allocates a percentage every time the player gets a level.
As @Nidoking points out, I don't see you chaanging upg here which would be the important part. What I am saying is why isn't this code something like:

GML:
with (oEnemyParent) {en_hp_max = round(en_hp_default * global.p_level)}
 
S

Stratos.la

Guest
the upg is in the create event of the object that controls everything in the game. and its a 0.4 % meaning i don't want the enemy hp going double the player hp but 40% more on every level up! i didn't get a chance to try out your suggestions guys but i will!
 
Top