Roblox错误:预期')'关闭'('在第3列),得到'='

时间:2016-07-29 10:00:19

标签: lua roblox

您好,我是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列的第一个,当我使用'=='而不是'='时,整行变为错误

1 个答案:

答案 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已经truefalse)与true进行比较有点愚蠢:而不是if x == true then ... end只需写{{ {1}}。