Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua Roblox错误:应为';)';关闭';(';在第3列),got'=';_Lua_Roblox - Fatal编程技术网

Lua Roblox错误:应为';)';关闭';(';在第3列),got'=';

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

嗨,我是Roblox上的一个用户,我正在尝试编写一个关闭4盏灯的灯光开关的脚本,我有一个错误(在标题中)

使用了两个模块,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列的第一个=,当我使用“==”而不是“=”时,整行都会变成错误,请尝试以下操作:

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
    )的值)
  • 是一个运算符,它期望其左右两侧出现条件
您的程序的形式是

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