Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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
Loops Roblox Lua中的褪色球_Loops_Lua_Roblox - Fatal编程技术网

Loops Roblox Lua中的褪色球

Loops Roblox Lua中的褪色球,loops,lua,roblox,Loops,Lua,Roblox,我正在尝试使球逐渐变为1透明度,然后再变回0。 这是我的密码: ball = script.Parent trans = 0 while true do if trans < 1 then while trans < 1 do ball.Transparency = trans wait(0.1) trans = trans + 0.1 end end if trans == 1 then while tra

我正在尝试使球逐渐变为1透明度,然后再变回0。 这是我的密码:

ball = script.Parent
trans = 0
while true do 
if trans < 1 then
    while trans < 1 do
        ball.Transparency = trans
        wait(0.1)
        trans = trans + 0.1 
    end
end
if trans == 1 then
    while trans <= 1 and trans >=0 do
        ball.Transparency = trans 
        wait(0.1)
        trans = trans -0.1 
    end
end
end

浮点精度:

0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1

不等于

1

我不确定当您将
trans
值指定给
ball.Transparency
时,为什么这不是一个因素

两件事:

1)
如果tostring(trans)=“1.0”,则
工作

2) 更好的是:为什么还要检查trans==1呢?当然会,因为前面的for循环保证了这一点


另外,请小心使用
,而“true”
…这可能是您的程序“冻结”的原因。

谢谢您的回答!我用while true,因为我想让它永远持续下去。我认为在它们之间使用等待将使它变得很好。我替换了if-ball。透明度加上if-true,它工作得非常完美D
while true do
ball = script.Parent
trans = 0
for i=0, 1, 0.1 do
    trans = i
    wait(0.1)
    ball.Transparency = trans
end
if ball.Transparency == 1 then
    for i = 1, 0, -0.1 do
        trans = i
        wait(0.1)
        ball.Transparency = trans
    end
end
end