【问题标题】:Roblox if Statement not runningRoblox if 语句未运行
【发布时间】:2019-03-05 21:01:55
【问题描述】:

我想知道是否可以通过我测试的这个小脚本获得一些帮助。 出于某种原因,if 语句未执行,这意味着即使值不等于 Rinzler,该函数也不会运行。 charData 是一个具体的 StringValue。

local charData = script.Parent.Data.CharacterData
local active = game.Workspace.Part

function change()
    if not charData.Value == "Rinzler" then
        charData.Value = "Rinzler"
        print("Character has changed to Rinzler.")
    end
end

active.Touched:Connect(change)

无论我做什么,"Character has changed to Rinzler" 都不会在控制台中打印。

【问题讨论】:

    标签: if-statement lua roblox


    【解决方案1】:

    问题出在if not charData.Value == "Rinzler"

    not 运算符在运算符优先级列表中的优先级高于 ==。 将该代码更新为:

    function change()
        if charData.Value ~= "Rinzler" then
            charData.Value = "Rinzler"
            print("Character has changed to Rinzler.")
        end
    end
    

    【讨论】:

    • 感谢@Vlad 的回答!
    • @Starflyer 这是您问题的答案吗?如果是这样,请将其标记为“已接受”,以便他因回答您的问题而获得声誉奖励。 (它也会给你一点!)
    猜你喜欢
    • 2019-02-26
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    • 2016-03-03
    • 1970-01-01
    相关资源
    最近更新 更多