【问题标题】:Roblox Studio ignoring my "If Statement" lineRoblox Studio 忽略了我的“If 语句”行
【发布时间】:2019-11-21 15:05:00
【问题描述】:

所以我有一个重复的脚本,不断检查一个值。但是,即使该值为 true,该函数也根本不会运行。

我尝试添加“wait()”来解决问题,但这根本不起作用。

useless = 0
wait(1)
repeat
    print("watno")
    wait()
    if script.Parent.Parent.Parent.windowsopen.Value == true then
        wait()
        for i = 5.5,0,0.1 do
            print("wat")
            wait()
            useless = useless + i
            script.Parent.Size = Vector3.new(script.Parent.Size.X, script.Parent.Y - 0.1, script.Parent.Size.Z )

        end
    elseif script.Parent.Parent.Parent.windowsopen.Value == false then

        wait()
    end
until false

“windowsopen”值始终为真,但它从不运行它。

【问题讨论】:

  • 你试过没有== true吗?并且您检查过Value 的类型,您可以通过使用type(script.Parent.Parent.Parent.windowsopen.Value) 并打印结果来做到这一点。
  • for 循环中的步骤看起来正在递增 - 而结束条件小于 5.5。
  • 为什么随机添加wait()会解决问题?!

标签: lua roblox


【解决方案1】:

问题很可能是由for 循环引起的,您应该将其更改为

      for i = 55, 0, -1 do
            print("wait")
            wait()
            useless = useless + 0.1*i
            script.Parent.Size = Vector3.new(script.Parent.Size.X, script.Parent.Y - 0.1, script.Parent.Size.Z )
        end

因为 (a) 如果你想在循环中减少 i 第三个参数应该是负数,(b) 你真的不应该在 for 循环中使用 floatdouble 因为精度\表示:0.1可能最终表示为 0.1000000000000001 (或类似的东西),并且 i 最终将永远不会在循环中等于零。有关更多信息,请检查 lua 用于表示 double 的格式(我认为它是 IEEE 754,但我可能错了)也可以查看 https://floating-point-gui.de/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 2020-06-22
    • 2019-03-05
    • 2015-11-27
    • 1970-01-01
    • 2013-09-15
    相关资源
    最近更新 更多