Lua Roblox错误:应为';)';关闭';(';在第3列),got'=';
嗨,我是Roblox上的一个用户,我正在尝试编写一个关闭4盏灯的灯光开关的脚本,我有一个错误(在标题中) 使用了两个模块,Off4和On4开关 我的代码是Lua Roblox错误:应为';)';关闭';(';在第3列),got'=';,lua,roblox,Lua,Roblox,嗨,我是Roblox上的一个用户,我正在尝试编写一个关闭4盏灯的灯光开关的脚本,我有一个错误(在标题中) 使用了两个模块,Off4和On4开关 我的代码是 function OnClicked() if (workspace.LivingRoomLight.SpotLight.Enabled == true) and (workspace.LivingRoomLight2.SpotLight.Enabled == true) and (workspace.LivingRoomLight3.Spo
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列的第一个=,当我使用“==”而不是“=”时,整行都会变成错误,请尝试以下操作:
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是否等于x==y
?”。这是一个条件(正确或错误)y
表示“将x=y
设置为x
”。这是一个语句(一个命令,用于修改y
)的值)x
是一个运算符,它期望其左右两侧出现条件和
if (these four values are true) then
set each of them to false
end
因此,第一行需要和以及=
,但是如果,它们在中没有意义-您需要使用=
的四个简单语句
不过,您并不真正需要=
。将布尔值(如workspace.LivingRoomLight.SpotLight.Enabled
,它们已经是true
或false
)与true
进行比较有点愚蠢:如果x==true,则不使用。。。结束
如果x然后。。。结束
只需将条件放在括号(if())中,而不是操作。工作非常完美!非常感谢。我很高兴:)你能接受我的回答吗✓) 那么你的问题就解决了吗?如果他们不理解如果,我的工作绝不是教他们for
。写那段代码很痛苦,但是初学者也应该有一次集中的问答体验——而OP的问题不是for
。