当前位置: 动力学知识库 > 问答 > 编程问答 >

lua - Variables not being replaced

问题描述:

I've been experimenting with the Lua Language and it seems as if all the variables are interacting with the conditions except for this one variable. Could take a look at it?

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

It prints:

-=Subject Reports=-

Subject: Marcy

Current Condition: Well (DefultValue)

Current Doctors: Dr. Pope, Dr.Roadmiller

Currently Recovering? Yes

You can afford this.

网友答案:

This part is broken

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

I bet you meant to do this:

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

regarding varSCondition: Your varSCondition is a String ("1"), but you're sometimes comparing it to integers (without the "-signs), for example here:

if varSCondition == 1 then

and sometimes to Strings , for example here:

if varSCondition == "20" then

All of them should be either a string, or an integer, but dont mix them. try this:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: