使框架可见是可能的,但是使无形的不是
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Frame.Visible == true then
script.Parent.Parent.Frame.Visible = false
end
if script.Parent.Parent.Frame.Visible == false then
script.Parent.Parent.Frame.Visible = true
end
end)
我是编码的新手(昨天实际上已经开始),我决定从Roblox Studio开始Lua。我可以向您保证该程序正在工作(代码中的某些事情可能不适合,因为我在本网站上编写代码有些麻烦),但是代码可以工作。我试图将其分别用于两个按钮,然后我尝试了一下,似乎没有用。我开始认为这是由程序本身引起的,而不是代码引起的,因为我可以使其他代码看不见其他内容。自从我被告知由代码引起的事件同时发生的事件以来,我将这两个可见性和隐身性的代码放在了1件事中,因此其中一些可能不起作用。
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Frame.Visible == true then
script.Parent.Parent.Frame.Visible = false
end
if script.Parent.Parent.Frame.Visible == false then
script.Parent.Parent.Frame.Visible = true
end
end)
I am very new to coding (have started practically yesterday ) and ive decided to start with lua in roblox studio. The program here is working i can assure you (some things in code may not be in proper place since im having a bit trouble writing code on this site) but the code works. I have tried to make it seperatly for 2 buttons then I tried this and nothing seems to work. I am starting to think it is caused by the program itself and not the code since I can make other things invisible with that code. I've placed those 2 codes for visibility and invisibility in 1 thing since I've been told that events caused by the code happen at same time so some of them may not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设
可见
是正确的。第一个条件将是真实的,<代码>可见将设置为false。然后,在下一个条件下可见
是错误的,因此条件是正确的。它将可见
设置为true。现在,为了修复它,您只需要在第一个失败时才执行第二个条件。看看
elseif
https://wwww.lua。 org/pil/4.3.1.html 。此代码仍然相当笨重,可以得到改进:
现在您将真实分配给
可见
如果可见
不评估为true。它基本上可以切换布尔值。Assume
Visible
is true. The first condition will be true andVisible
will be set to false. Then, in the next conditionVisible
is false and the condition is therefore true, again. And it setsVisible
back to true.Now, in order to fix it you want to execute the second condition only if the first failed. Take a look at
elseif
https://www.lua.org/pil/4.3.1.html.This code is still quite bulky and can be improved:
Now you assign true to
Visible
ifVisible
does not evaluate to true. It basically toggles the boolean.