游戏制作者无法识别变量

发布于 2024-10-31 16:31:39 字数 1217 浏览 7 评论 0原文

尝试在 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

然后在玩家的步骤事件中运行此代码字符:

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 无法识别该变量吗?

Attempting to set up a targeting array for a MMO-style game in GameMaker8 Pro, I have this code in the create event for the player's character, which is and has been running perfectly fine:

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

Then running this code in the step event for the player character:

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}

Returns this error message:

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

Even though I have this in the create event for the enemy:

range = 0
range = distance_to_object(rk)

And I've used this sort of syntax all over:

global.target[target].threat[s] += damage

Help? Any ideas why Game Maker won't recognize the variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

万劫不复 2024-11-07 16:31:39

我最好的猜测是,在玩家创建事件和发生错误的步骤事件之间,一个或多个敌人实例已被摧毁。也许更好的解决方案是使用 with() 构造迭代所有敌人,这样速度更快,并且您可以确保您正在使用的所有实例实际上都存在。

My best guess is that one or more of the enemy instances have been destroyed between the player create event and the step event where the error happens. Maybe a better solution would be to iterate over all the enemies using the with() construct, that is faster and you can be sure that all the instances you are working with actually exist.

遥远的她 2024-11-07 16:31:39

尝试将对象变量放在括号中。我之前在参考扩展中遇到过麻烦。

(global.ttarget[g]).range

或者甚至将其保存到一个新变量中

for (g = 0; g<global.rmtargets; g+=1)
{
    curr_target = global.ttarget[g]
    curr_target.range
}

try putting brackets around the object variable. I have had trouble references from a reference extension before.

(global.ttarget[g]).range

or even save it to a new variable

for (g = 0; g<global.rmtargets; g+=1)
{
    curr_target = global.ttarget[g]
    curr_target.range
}
权谋诡计 2024-11-07 16:31:39

而不是使用全局。在代码中变量的每个实例之前,您还可以使用以下命令对其进行初始化:

globalvar (variable), (variable2);

然后您就可以在没有全局的情况下使用该变量。在它前面:)

如果对象 rk 不是敌人,则对象 rk 无法检测到全局范围变量。没有 var 或 globalvar 初始化的变量仅适用于定义它的对象。

Instead of using global. before each instance of the variable in the code, you could also initialize it with the command:

globalvar (variable), (variable2);

Then you would be able to use the variable without global. in front of it :)

If object rk is not the enemy then there is no global range variable detectable by object rk. Variables initialized without var or globalvar only apply for the object it was defined in.

暗地喜欢 2024-11-07 16:31:39

首先,在 if 条件中放入圆括号。

其次,您应该提供有关您的环境和编程逻辑的更多信息,并且 IMO 停止使用所有这些全局变量

无论如何,根据我对你正在做的事情的理解,尝试使用 with 关键字:

with(global.ttarget[g]) {

other.hv = range;

}

First of all, put round brackets in if conditions.

Second you should give more informations about your environment and programming logic and IMO stop using all these global variables.

Anyway, from what i understood of what you're doing, try to use the with keyword:

with(global.ttarget[g]) {

other.hv = range;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文