2016-07-29 43 views
1

您好我在Roblox用户和我试图脚本一个光开关,其关闭4个灯和我有一个误差(它是在标题)Roblox错误:预期“)”关闭“(”在第3列),得到了“=”

有正在使用的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) 

注:我只用在脚本,因为这是我唯一编辑的错误之一。在脚本中的错误是第一=在第3栏,当我使用“==”,而不是“=”,那么整条生产线变成了错误

+0

只要将条件放在括号(if())而不是操作中。 –

回答

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表示“不等于xy?”。这是条件(无论是true还是false)。
  • x = y手段“设置xy”。这是一个声明(您的程序修改值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只是写if x then ... end更好。

+0

完美工作!谢谢! – Austinsoevil81

+0

我很高兴:)你能接受我的答案(点击✓),以便你的问题显示为已解决? – Lynn

+0

如果他们不明白'如果',我绝不会教他们关于'for'的工作。编写这段代码会很麻烦,但初学者也应该有一个专注的问答体验 - 而OP的问题不是关于“for”。 – Lynn

相关问题