我有兩個問題,一個是lua中的回報是什麼?我一直在搜索整個互聯網尋找它/它的手段和它的purpouse。 2.我無法編碼本節:什麼是回報和我做錯了什麼(Lua)
testGrade={}
testGrade.Joe = 86
testGrade.Josh = 75
testGrade.Jack = 12
testGrade.Andrew = 0
testGrade.Larry = 100
testGrade.Noah = 94
testGrade.Blakely = 67
for k,v in pairs(testGrade) do
local maxGrade = 100
if testGrade[grade] == 100 then
Msg("Congratulations "..k..", you scored a "..v.." out of "..maxGrade.." getting every question right!\n");
elseif testGrade[grade] >= 90 then
Msg("Congratulations "..k..", you scored a "..v.." out of "..maxGrade.." getting an A!\n");
elseif testGrade[grade] >= 80 then
Msg(k..", you scored a "..v.." out of "..maxGrade.." getting a B.\n");
elseif testGrade[grade] >= 70 then
Msg(k..", you scored a "..v.." out of "..maxGrade.." getting a C, try harder next time.\n");
elseif testGrade[grade] >= 60 then
Msg(k..", you scored a "..v.." out of "..maxGrade.." getting a D, you need to study!\n");
elseif testGrade[grade] == 0 then
Msg(k..", you scored a "..v.." out of "..maxGrade.." getting NOTHING right! Did you even try?!\n");
else
Msg(k..", you scored a "..v.." out of "..maxGrade.." making you fail. You need to try harder and study!\n");
end
end
我試圖做一些練習編碼,但還是難住了這一點。評論是非常有用的;)
它從一個函數返回一個值。從[2.4.4控制結構](http://www.lua.org/manual/5.1/manual.html#2.4.4):「返回語句用於返回函數或塊的值(這是隻是一個函數)函數和塊可以返回多個值返回語句用於從函數或塊返回值(這只是一個函數)函數和塊可以返回多個值...「。 – 2014-12-11 04:51:41
好像你想用'v'來代替'testGrade [grade]'的每一種情況。您在其他地方使用'k'和'v',所以我不確定斷開連接的位置。 – 2014-12-11 04:56:46
@退休的忍者啊,對不起。我忘了改變那部分。我使用了以前使用的舊版過時代碼,在學習其他循環策略之前,我將等級作爲變量使用。真的很累atm並沒有發現。我很困惑哈哈。 – laws16 2014-12-11 05:03:04