尝试在 GameMaker8 Pro 中为 MMO 风格的游戏设置目标数组,我在玩家角色的创建事件中有此代码,该代码运行良好,并且一直运行良好:
j = 0
i = 0
g = 0
for (i=100000; i<1000000; i+=1) if instance_exists(i) {if i.object_index = enemy {global.ttarget[j] = i j+=1} if i.object_index = rk or i.object_index = sage {global.etarget[g] = i g += 1}}
global.rmtargets = j
global.etargets = g
然后在玩家角色的 step 事件中运行此代码:
h = 0
g = 0
i = 0
for (i=0; i<global.rmtargets; i+=1) global.target[i] = 0
global.target[0]=101139
for (h = 0; h<global.rmtargets; h+=1){hv = -1
for (g = 0; g<global.rmtargets; g+=1){if global.ttarget[g].range > hv {hv = global.ttarget[g].range}}
global.target[h] = hv
global.ttarget[h] = -1}
返回此错误消息:
ERROR in
action number 1
of Step Event
for object rk:
Error in code at line 8: for (g = 0; g<global.rmtargets; g+=1){if global.ttarget[g].range > hv {hv = global.ttarget[g].range}}
at position 61: Unknown variable range
即使我在敌人的创建事件中有这个:
range = 0
range = distance_to_object(rk)
而且我一直使用这种语法:
global.target[target].threat[s] += damage
帮助?任何想法为什么 Game Maker 无法识别该变量?