2014-12-11 92 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的評論,他教會了我一些新的東西;)