2014-12-11 91 views
2

我编码,我这里得到一个错误:这个lua编码有什么问题?

Ammo = 450 
Rocket = 20 
Money = 35041 
--Can I attend this mission? 
function attendMission() 
    if Ammo >= 400 or Rocket >= 35 and Money >= 30000 then 
     return Money = Money - 30000 
     Msg("Attending Mission\n") 
     Msg("You now have "..Money.." dollars\n") 
    else 
     Msg("You do not have the resources to attend this mission\n") 
    end 
end 
print(attendMission()) 
--Ammo Amount 
function whatIsAmmo() 
    if Ammo > 0 then 
     print("You have "..Ammo.." Ammo") 
    else 
     Msg("You have no Ammo") 
    end 
end 
print(whatIsAmmo()) 
--Rocket Amount 
function whatIsRocket() 
    if Rocket > 0 then 
     Msg("You have "..Rocket.." rockets") 
    else 
     Msg("You have no rockets") 
    end 
end 
print(whatIsRocket()) 
--Money Amount 
function whatIsMoney() 
    if Money > 100000 then 
     Msg("You have "..Money.." dollars, wow your rich!") 
    elseif Money > 0 then 
     Msg("You have "..Money.." dollars") 
    else 
     Msg("You have no money") 
    end 
end 
print(whatIsMoney()) 

它说,有预计近期=结束。我一直在寻找一段时间,但我不知道如何解决它。我已经缩小了错误在这一部分,虽然:

function attendMission() 
    if Ammo >= 400 or Rocket >= 35 and Money >= 30000 then 
     return Money = Money - 30000 
     Msg("Attending Mission\n") 
     Msg("You now have "..Money.." dollars\n") 
    else 
     Msg("You do not have the resources to attend this mission\n") 
    end 
end 
+4

在Lua中(与C和其他一些语言不同),赋值是一个语句,而不是表达式。 – 2014-12-11 00:58:53

+0

好吧,我这样做了,但是现在我在'Msg'附近得到''end''(如果'在6号线关闭')' – laws16 2014-12-11 00:59:52

+4

'return'也需要是块中的最后一个语句(至少在lua中5.1)。所以这必须是该区块的最后一行。尽管你可以使用'do return end'来强制一个块使其工作。 – 2014-12-11 01:00:25

回答

1

我刚刚发现问题是什么。显然回移一些词来创建:

Ammo = 450 
Rocket = 20 
Money = 35041 
--Can I attend this mission? 
function attendMission() 
if Ammo >= 400 or Rocket >= 35 and Money >= 30000 then 
    Msg("Attending Mission\nYou now have "..Money.." dollars\n") 
    Money = Money - 30000 
else 
    Msg("You do not have the resources to attend this mission\n") 
end 
end 
print(attendMission()) 
--Ammo Amount 
function whatIsAmmo() 
if Ammo > 0 then 
    print("You have "..Ammo.." Ammo") 
else 
    Msg("You have no Ammo") 
end 
end 
print(whatIsAmmo()) 
--Rocket Amount 
function whatIsRocket() 
if Rocket > 0 then 
    Msg("You have "..Rocket.." rockets") 
else 
    Msg("You have no rockets") 
end 
end 
print(whatIsRocket()) 
--Money Amount 
function whatIsMoney() 
if Money > 100000 then 
    Msg("You have "..Money.." dollars, wow your rich!") 
elseif Money > 0 then 
    Msg("You have "..Money.." dollars") 
else 
    Msg("You have no money") 
end 
end 
print(whatIsMoney()) 

像这样完美的工作。但是,谢谢你们帮助我!尤其是你对Josh的评论,他教会了我一些新的东西;)