您好,我是Roblox的用户,我正在尝试编写一个关闭4个灯的灯开关,我遇到了错误(它在标题中)
有2块正在使用,Off4和On4开关。
我的代码是
function OnClicked()
if (workspace.LivingRoomLight.SpotLight.Enabled == true) and (workspace.LivingRoomLight2.SpotLight.Enabled == true) and (workspace.LivingRoomLight3.SpotLight.Enabled == true) and (workspace.LivingRoomLight4.SpotLight.Enabled == true) then
(workspace.LivingRoomLight.SpotLight.Enabled = false) and (workspace.LivingRoomLight2.SpotLight.Enabled == false) and (workspace.LivingRoomLight3.SpotLight.Enabled == false) and (workspace.LivingRoomLight3.SpotLight.Enabled == false)
script.Parent.Transparency = 1
workspace.Off4.Transparency = 0
end
end
script.Parent.ClickDetector.MouseClick:connect(OnClicked)
我在仅使用一个灯光的那些脚本中使用的其他脚本是
function OnClicked()
if (workspace.Hallwaylight.SpotLight.Enabled == true) then
workspace.Hallwaylight.SpotLight.Enabled = false
script.Parent.Transparency = 1
workspace.Off.Transparency = 0
end
end
script.Parent.ClickDetector.MouseClick:connect(OnClicked)
注意:我只使用on脚本,因为这是我为有错误的脚本编辑的唯一脚本。 on脚本中的错误是第3列的第一个,当我使用'=='而不是'='时,整行变为错误
答案 0 :(得分:1)
试试这个:
if (workspace.LivingRoomLight.SpotLight.Enabled == true) and (workspace.LivingRoomLight2.SpotLight.Enabled == true) and (workspace.LivingRoomLight3.SpotLight.Enabled == true) and (workspace.LivingRoomLight4.SpotLight.Enabled == true) then
workspace.LivingRoomLight.SpotLight.Enabled = false
workspace.LivingRoomLight2.SpotLight.Enabled = false
workspace.LivingRoomLight3.SpotLight.Enabled = false
workspace.LivingRoomLight4.SpotLight.Enabled = false
...
一些指示:
x == y
表示“x
等于y
?”。这是条件(无论是真还是假)。x = y
表示“将x
设为y
”。这是声明(程序中修改x
值的命令)。and
是一个运营商,其左右都需要条件。您的计划格式为
if (these four values are true) then
set each of them to false
end
所以你在第一行需要and
和==
,但它们在if
内没有意义 - 你需要使用=
的四个简单语句,那里
你并不是真的需要 ==
。将布尔值(例如workspace.LivingRoomLight.SpotLight.Enabled
已经true
或false
)与true
进行比较有点愚蠢:而不是if x == true then ... end
只需写{{ {1}}。