游戏制作者的这段代码无法正常工作:

时间:2015-06-01 23:22:39

标签: game-maker gml

此代码确实在其健康状况达到0时销毁该对象,但它不会将5/7添加到global.xp变量。

if rotem_hp > 1 and shop_13 = 0
{   
rotem_hp = rotem_hp -1
}
else
{
if rotem_hp > 1 and shop_13 = 1 rotem_hp = rotem_hp -1.5
if rotem_hp < 1 and shop_4 = 0 global.xp = global.xp + 5 instance_destroy()
if rotem_hp < 1 and shop_4 = 1 global.xp = global.xp + 7 instance_destroy()
}

这不会起作用

if (rotem_hp > 1 and global.shop_13 = 0)
{   
rotem_hp = rotem_hp -1
}
else if (rotem_hp > 1 and global.shop_13 = 1) 
{
rotem_hp = rotem_hp -1.5
}
else if (rotem_hp < 1 and global.shop_4 = 0) 
{
global.xp = global.xp +5 
instance_destroy()
}
else if (rotem_hp < 1 and global.shop_4 = 1)
{
global.xp = global.xp +7 
instance_destroy()
}
else
{
//do nothing
}

这不会破坏对象(在我创建的事件中有btw(rotem_hp = 5)

if rotem_hp > 1 and global.shop_13 = 0
{
rotem_hp = rotem_hp -1 
}

if rotem_hp > 1 and global.shop_13 = 1
{
rotem_hp = rotem_hp -1.5
}

if rotem_hp < 1 and global.shop_4 = 0
{
global.xp = global.xp +5 
instance_destroy()
}

if rotem_hp < 1 and global.shop_4 = 1
{
global.xp = global.xp +7
instance_destroy()
}

我将非常感谢能够回答我的问题。

2 个答案:

答案 0 :(得分:1)

写作时

if rotem_hp < 1 and shop_4 = 0 global.xp = global.xp + 5 instance_destroy()
if rotem_hp < 1 and shop_4 = 1 global.xp = global.xp + 7 instance_destroy()

意味着

if rotem_hp < 1 and shop_4 = 0
{
    global.xp = global.xp + 5
}
instance_destroy()

if rotem_hp < 1 and shop_4 = 1 
{
    global.xp = global.xp + 7
}
instance_destroy()

所以最后if会更新,因为该对象已被销毁。 您需要使用曲线括号来定义if范围。

您可以这样写:

if rotem_hp < 1 and shop_4 = 0
{
    global.xp += 5
    instance_destroy()
}

if rotem_hp < 1 and shop_4 = 1 
{
    global.xp += 7
    instance_destroy()
}

或者如果你想只需要一行,如果&#39;

if rotem_hp < 1 and shop_4 = 0 { global.xp += 5; instance_destroy(); }
if rotem_hp < 1 and shop_4 = 1 { global.xp += 7; instance_destroy(); }

答案 1 :(得分:0)

好的,对于遇到与我相同问题的每个人:

我终于设法解决了这个问题,问题在于我用过:

if rotem_hp > 1
{   
rotem_hp = rotem_hp -1
}

而不是:

if rotem_hp >= 1
{   
rotem_hp = rotem_hp -1
}

因此当&#34; rotem&#34;的健康状况恰好达到1时,代码不知道该做什么,因为我告诉它当&gt; 1和&lt; 1时做的事情,这就是这样的愚蠢的问题,我不能相信我浪费了几分钟来解决它,我现在将躲在我房间的角落里充满羞耻。再见。