Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ipairs循环始终只返回lua中的一个值?_Lua_Roblox - Fatal编程技术网

ipairs循环始终只返回lua中的一个值?

ipairs循环始终只返回lua中的一个值?,lua,roblox,Lua,Roblox,快速编辑:_G.i是我设置为创建24小时时间框架的1-24表。它全局存储在第三级脚本中,实现方式如下: _G.i = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24} 因此,我试图让这个循环与我创建的昼夜循环一起工作。我希望循环不断地检查时间,并根据我设置的几个参数将时间打印到控制台 light = script.Parent.lightPart.lightCone t

快速编辑:_G.i是我设置为创建24小时时间框架的1-24表。它全局存储在第三级脚本中,实现方式如下:

_G.i = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}
因此,我试图让这个循环与我创建的昼夜循环一起工作。我希望循环不断地检查时间,并根据我设置的几个参数将时间打印到控制台

light = script.Parent.lightPart.lightCone
timeofday = ""
wait(1)

function checkTime()
    for i, v in ipairs(_G.i) do
        wait(1)
        print(v)
        print(timeofday)
        if v > 20 and v < 6 then
            timeofday = "night"
        else
            timeofday = "day"
        end 
    end
end  

while true do
    checkTime()
    wait(1)
end

很抱歉,如果这篇文章很草率或者代码很草率,我对这两个都是新手。我一直在尝试自己解决这个问题,并且一直做得很好。最初我不知道ipairs循环是什么,但我设法让它在昼夜循环中工作,而不是无限等待(1)循环

您的问题是:

if v > 20 and v < 6 then

您这样做的问题在于,您假定
checkTime()
函数将始终在
changeTime()
函数之后运行,但情况并非如此。

您的问题在于:

if v > 20 and v < 6 then

您这样做的问题是,您假设
checkTime()
函数将始终在
changeTime()
函数之后运行,这不一定是这样的。

您可以包含填充
\u G.i
的代码吗?是的,非常简单,这就是脚本包含的所有
\u G.i={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}
你能把你填充的代码包括进去吗?
\G.i
?是的,非常简单这就是脚本包含的所有内容
\G.i={1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,22,23,24}
非常感谢!我知道这与那一行有关,但我太想弄明白了,让简单的逻辑从脑海中溜走了。我还将加入更简单的循环,因为它可能会在以后帮助我。谢谢!非常感谢!我知道这与那一行有关,但我太想弄明白了我忘记了简单的逻辑。我还将添加到更简单的循环中,因为它以后可能会对我有所帮助。谢谢!
light = script.Parent.lightPart.lightCone
current_time = 0

function checkTime()
    print(current_time)
    if current_time > 20 or current_time < 6 then
        timeofday = "night"
    else
        timeofday = "day"
    end 
    print(timeofday)
end  

while true do
    checkTime()
    wait(0.1)
end


function changeTime()
    for v = 1, 24 do
        game.Lighting:SetMinutesAfterMidnight(v * 60)
        current_time = v
    end
end

while true do
    changeTime()
    wait(1)
end