2016-07-29 82 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

相關問題