【问题标题】:This code in game maker won't work properly:游戏制作器中的此代码将无法正常工作:
【发布时间】:2015-06-24 11:57:42
【问题描述】:

此代码会在其生命值达到 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()
}

感谢您为回答我的问题所做的任何努力。

【问题讨论】:

  • 您可以更新您的答案以包含添加为注释的代码
  • 什么问题?你想要什么? shop_13shop_4 是什么?你用了什么活动?
  • Global.shop 变量是当我在商店购买东西时,它会将其变量设置为 1 而不是 0,因为它是真的(布尔值或其他东西)。
  • 它可以提供额外伤害或经验值,如您所见

标签: game-maker gml


【解决方案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()
}

或者如果你想要一个'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(); }

【讨论】:

    【解决方案2】:

    好的,对于遇到和我一样问题的每个人:

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

    if rotem_hp > 1
    {   
    rotem_hp = rotem_hp -1
    }
    

    代替:

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

    所以当“rotem”的生命值正好达到 1 时,代码不知道该做什么,因为我告诉它在 >1 和

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 2019-01-15
      相关资源
      最近更新 更多