变量没有被替换。

我一直在尝试使用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.
点赞
用户3213368
用户3213368

这部分出错了

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"),但有时将其与整数进行比较(没有引号),例如此处:

if varSCondition == 1 then

有时与字符串进行比较,例如此处:

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
2014-01-20 03:44:23