使框架可见是可能的,但是使无形的不是

发布于 2025-02-11 19:38:59 字数 528 浏览 1 评论 0原文

      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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过度放纵 2025-02-18 19:38:59

假设可见是正确的。第一个条件将是真实的,<代码>可见将设置为false。然后,在下一个条件下可见是错误的,因此条件是正确的。它将可见设置为true。

现在,为了修复它,您只需要在第一个失败时才执行第二个条件。看看elseif https://wwww.lua。 org/pil/4.3.1.html

script.Parent.MouseButton1Click:Connect(function()
    if script.Parent.Parent.Frame.Visible == true then
        script.Parent.Parent.Frame.Visible = false
    elseif script.Parent.Parent.Frame.Visible == false then
        script.Parent.Parent.Frame.Visible = true
    end
end)

此代码仍然相当笨重,可以得到改进:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible
end)

现在您将真实分配给可见如果可见不评估为true。它基本上可以切换布尔值。

Assume Visible is true. The first condition will be true and Visible will be set to false. Then, in the next condition Visible is false and the condition is therefore true, again. And it sets Visible 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.

script.Parent.MouseButton1Click:Connect(function()
    if script.Parent.Parent.Frame.Visible == true then
        script.Parent.Parent.Frame.Visible = false
    elseif script.Parent.Parent.Frame.Visible == false then
        script.Parent.Parent.Frame.Visible = true
    end
end)

This code is still quite bulky and can be improved:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible
end)

Now you assign true to Visible if Visible does not evaluate to true. It basically toggles the boolean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文