Roblox Studio Lua 循环中的 if 语句
Roblox Studio Lua if-statement in loop
我在这个游戏中有一个 Roblox 游戏,使用 Roblox 开发者网站上的代码更改时间(robloxdev.com)我一直在用两个名为 "open" 和 [=20 的工会制作一扇门=].我希望门在早上 10 点到晚上 5 点之间打开。然而,门打不开,甚至在适当的时候也没有显示 open/close。
这是我当前的代码注意:脚本与两个联合在同一模型(称为:Door)中。
while true do
if game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 17 then
--Open the door
print("open")
script.Parent.Closed.Transparency = 1
script.Parent.Closed.CanCollide = false
script.Parent.Open.Transparency = 0
script.Parent.Open.CanCollide = true
else
--Close the door
print("close")
script.Parent.Closed.Transparency = 0
script.Parent.Closed.CanCollide = true
script.Parent.Open.Transparency = 1
script.Parent.Open.CanCollide = false
end
end
感谢您的帮助。
您应该在 while 循环中添加等待。
while true do
if game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 17 then
--Open the door
print("open")
script.Parent.Closed.Transparency = 1
script.Parent.Closed.CanCollide = false
script.Parent.Open.Transparency = 0
script.Parent.Open.CanCollide = true
else
--Close the door
print("close")
script.Parent.Closed.Transparency = 0
script.Parent.Closed.CanCollide = true
script.Parent.Open.Transparency = 1
script.Parent.Open.CanCollide = false
end
wait(1) -- change this to whatever you want
end
我在这个游戏中有一个 Roblox 游戏,使用 Roblox 开发者网站上的代码更改时间(robloxdev.com)我一直在用两个名为 "open" 和 [=20 的工会制作一扇门=].我希望门在早上 10 点到晚上 5 点之间打开。然而,门打不开,甚至在适当的时候也没有显示 open/close。
这是我当前的代码注意:脚本与两个联合在同一模型(称为:Door)中。
while true do
if game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 17 then
--Open the door
print("open")
script.Parent.Closed.Transparency = 1
script.Parent.Closed.CanCollide = false
script.Parent.Open.Transparency = 0
script.Parent.Open.CanCollide = true
else
--Close the door
print("close")
script.Parent.Closed.Transparency = 0
script.Parent.Closed.CanCollide = true
script.Parent.Open.Transparency = 1
script.Parent.Open.CanCollide = false
end
end
感谢您的帮助。
您应该在 while 循环中添加等待。
while true do
if game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 17 then
--Open the door
print("open")
script.Parent.Closed.Transparency = 1
script.Parent.Closed.CanCollide = false
script.Parent.Open.Transparency = 0
script.Parent.Open.CanCollide = true
else
--Close the door
print("close")
script.Parent.Closed.Transparency = 0
script.Parent.Closed.CanCollide = true
script.Parent.Open.Transparency = 1
script.Parent.Open.CanCollide = false
end
wait(1) -- change this to whatever you want
end