I'm just trying to change a simple object's variable from within my script. The code runs but does nothing to change the variable.
Editing this variable should lower the enemy's health bar, but it does not. If I edit this variable from within the object itself the healthbar changes.
enemies();
friends();
randomize();
//get enemy from array and make an instance
active_enemy = enemy_list[irandom_range(0, 1)];
var inst1 = instance_create_depth(200, 75, 1, active_enemy);
//get friend from arrayand make an instance
active_friend = friend_list[irandom_range(0, 1)];
var inst2 = instance_create_depth(96, 175, 1, active_friend);
//change variable
inst1.e_health_active = 1;
This script is placed in the battle room creation code and e_health_active is in every enemy obj code as part of their stats.
Thanks!
If you make the enemies health variable global by doing this global.e_health_active = 1;
within a persistent Game
object that is placed in the starting room, global.e_health_active
will be now accessible anywhere within the programme. It won't have to be in the same object anymore.
Do something like this:
// Persistent game object - where you would like to store all your global variables
// Create event
global.e_health_active = 10; // this can be any number you want it to be.
Then you put the following in your battle room creation code
// Creation code of battle room
enemies();
friends();
randomize();
//get enemy from array and make an instance
active_enemy = enemy_list[irandom_range(0, 1)];
var inst1 = instance_create_depth(200, 75, 1, active_enemy);
//get friend from arrayand make an instance
active_friend = friend_list[irandom_range(0, 1)];
var inst2 = instance_create_depth(96, 175, 1, active_friend);
//change variable
inst1.global.e_health_active = 1;