0

このコードは、ヘルスが 0 になるとオブジェクトを破棄しますが、global.xp 変数に 5/7 を追加しません。

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

または、1 つの 'if' に対して 1 行だけが必要な場合

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 に答える