我一直在尝试使用Lua语言,似乎所有变量都与除了这一个变量之外的条件相互作用。可以看一下吗?
function Medicial()
local varName = "Marcy"
local varCondition = "Well"
local varSCondition = "1" -- 5 = Uncurable, 10 = Well, 15 = Unknown, 20 = Surgery, 25 = Post Surgery, 29 = Bar Surgery
local varDoctors = "DefultValue"
local varExStatus = "DefultValue"
local payment = "You can afford this."
local total = 400
if varCondition == "Well" then
varDoctors = "Dr. Pope, Dr.Roadmiller"
varStatus = "Yes"
end
if varCondition == "Sick" then
varDoctors = "Dr. Pope, Dr.Rosenhour, Surgeon Rossford"
varStatus = "No"
end
if total > 1000 then
payment = "You can not afford this."
elseif total >= 1000 then
payment = "You can affort this, but you will be broke."
end
if varSCondition == 1 then
varExStatus = "Well"
end
if varSCondition == 5 then
varExStatus = "Uncurable"
end
if varSCondition == 15 then
varExStatus = "Unknown"
end
if varSCondition == "20" then
varExStatus = "Surgery"
end
if varSCondition == "25" then
varExStatus = "Post Surgery"
end
if varSCondition == "29" then
varExStatus = "Bar Surgery"
end
print("-=Subject Reports=-\n");
print("Subject: "..varName.."\nCurrent Condition: "..varCondition.." ("..varExStatus..")\nCurrent Doctors: "..varDoctors.."\nCurrently Recovering? "..varStatus);
print(">> "..payment);
end
打印:
-=Subject Reports=-
Subject: Marcy
Current Condition: Well (DefultValue)
Current Doctors: Dr. Pope, Dr.Roadmiller
Currently Recovering? Yes
You can afford this.
答案 0 :(得分:3)
此部分已损坏
if total > 1000 then
payment = "You can not afford this."
elseif total >= 1000 then
payment = "You can affort this, but you will be broke."
end
我打赌你打算这样做:
if total < 1000 then
payment = "You can not afford this."
elseif total == 1000 then
payment = "You can affort this, but you will be broke."
end
关于varSCondition:你的varSCondition是一个字符串(“1”),但你有时将它与整数(没有“-signs”)比较,例如:
if varSCondition == 1 then
有时候是Strings,例如:
if varSCondition == "20" then
所有这些都应该是字符串或整数,但不要混合它们。试试这个:
local varSCondition = 1 -- 5 = Uncurable, 10 = Well, 15 = Unknown, 20 = Surgery, 25 = Post Surgery, 29 = Bar Surgery
...
if varSCondition == 1 then
varExStatus = "Well"
end
if varSCondition == 5 then
varExStatus = "Uncurable"
end
if varSCondition == 15 then
varExStatus = "Unknown"
end
if varSCondition == 20 then
varExStatus = "Surgery"
end
if varSCondition == 25 then
varExStatus = "Post Surgery"
end
if varSCondition == 29 then
varExStatus = "Bar Surgery"
end