Lua 为什么不是';t此代码将变量更改为True或False 问题
所以现在,我正在用Roblox做一个游戏。我正在开发我的一个GUI,但是代码没有改变我正在使用的名为Lua 为什么不是';t此代码将变量更改为True或False 问题,lua,roblox,Lua,Roblox,所以现在,我正在用Roblox做一个游戏。我正在开发我的一个GUI,但是代码没有改变我正在使用的名为state的变量。state变量应该告诉您它是打开的还是关闭的(如果打开,state将=true,否则state将=false) 我已经尝试将变量设置为局部变量,但仍然是相同的输出。我通过打印状态变量来检查输出,该变量始终与默认值相同 代码 我希望代码的输出将varstate在打开时设置为True,在关闭时设置为False。在帧:TweenPosition(UDim2.new(0.3,0,1.2,
state
的变量。state变量应该告诉您它是打开的还是关闭的(如果打开,state将=true,否则state将=false)
我已经尝试将变量设置为局部变量,但仍然是相同的输出。我通过打印状态
变量来检查输出,该变量始终与默认值相同
代码
我希望代码的输出将var
state
在打开时设置为True,在关闭时设置为False。在帧:TweenPosition(UDim2.new(0.3,0,1.2,0))
行之后缺少state=False
。在将其值更改为true
后,您永远不会将其值切换回false
。您需要注意如何连接鼠标1单击事件侦听器
当您自上而下阅读脚本时,您将看到,由于State
以false开头,因此您连接的唯一侦听器是第二个侦听器。这意味着,当您单击按钮时,它将只在帧之间进入打开状态。最好编写一次单击处理程序,在每次单击时处理此逻辑
local Button = script.Parent.Button
local Frame = script.Parent.Parent.Parent.Parent.Parent.MinerGuiManager.MinerFrame
State = false
Button.MouseButton1Click:connect(function()
if State == true then
Button.Text = 'Close!'
Frame:TweenPosition(UDim2.new(0.3,0,1.2,0))
else
Button.Text = 'Open!'
Frame:TweenPosition(UDim2.new(0.305,0,0.25,0,'Bounce',1.5))
end)
State = not State
end)
Lua变量区分大小写,在编辑中,您将其置于
状态而不是状态
-但这并不能解决您的问题。您添加了一个不同的变量(状态
),而不是您在其他位置使用的变量(状态
)。当我将其置于Roblox中时,Roblox输出一个错误,上面写着“`Expected Identifier get')”``这显示在末尾)
。很抱歉输入错误。我忘了关闭连接功能。将更新答案
local Button = script.Parent.Button
local Frame = script.Parent.Parent.Parent.Parent.Parent.MinerGuiManager.MinerFrame
State = false
Button.MouseButton1Click:connect(function()
if State == true then
Button.Text = 'Close!'
Frame:TweenPosition(UDim2.new(0.3,0,1.2,0))
else
Button.Text = 'Open!'
Frame:TweenPosition(UDim2.new(0.305,0,0.25,0,'Bounce',1.5))
end)
State = not State
end)