0

此代码会在其运行状况达到 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
}

这不会破坏对象(顺便说一句,我有创建事件(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()
}

我将感谢任何努力回答我的问题。

4

2 回答 2

2

当你写

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()
}

或者如果你只想要一个'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(); }
于 2015-06-02T03:43:07.683 回答
0

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

我终于设法解决了这个问题,问题是我使用了:

if rotem_hp > 1
{   
rotem_hp = rotem_hp -1
}

代替:

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

所以当“rotem”的健康值恰好达到 1 时,代码不知道该怎么做,因为我告诉它在 >1 和 <1 时做一些事情,这是一个愚蠢的问题,我不敢相信我浪费了超过几分钟为了解决它,我现在会羞愧地躲在我房间的角落里。再见。

于 2015-06-02T11:40:30.947 回答