无法从单独的脚本编辑对象变量

Can't edit object variable from a seperate script

我只是想在我的脚本中更改一个简单对象的变量。代码运行但未更改变量。

编辑这个变量应该会降低敌人的生命值,但事实并非如此。如果我从对象本身内部编辑此变量,则健康栏会发生变化。

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;

此脚本放置在战斗室创建代码中,e_health_active作为其统计数据的一部分存在于每个敌人对象代码中。

谢谢!

如果你通过在放置在起始房间的永久性 Game 对象中执行此 global.e_health_active = 1; 使敌人的健康变量成为全局变量,现在 global.e_health_active 将可以在房间内的任何地方访问程序。它不必再在同一个对象中。

做这样的事情:

// 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. 

然后将以下内容放入战斗室创建代码

// 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;