【问题标题】:GUI Shop with multiple buttons, equip item, buy item, and check if already has itemGUI商店有多个按钮,装备物品,购买物品,并检查是否已有物品
【发布时间】:2016-05-22 21:21:56
【问题描述】:

我发布的代码是为了做三件事:

  1. 按下 buyButton 时将 item.DoesOwn.Value 设置为 true
  2. item.DoesOwn.Value 为真时使equipButton 可见
  3. 取消装备所有物品,然后在按下装备时装备所选物品。

问题:当我单击多个项目按钮,然后单击buyButton 时,它会将所有按钮的DoesOwn.Value 属性设置为true。我只想一次购买一件物品,而且前提是它尚未拥有。当他们已经拥有该物品时,一次装备一件物品也是如此。

previewBox=script.Parent.PreviewImage
itemLabel=script.Parent.ItemName
priceLabel=script.Parent.PriceLabel

equipButton=script.Parent.Equip
buyButton=script.Parent.Buy

knifeItems=script.Parent.KnifeFrame:GetChildren()

function checkKnifeItems(button,buttons)
    previewBox.Image=button.Image
    itemLabel.Text=button.Name

    if button.DoesOwn.Value == true and button.Equipped.Value == false then 

        priceLabel.Visible=false
        equipButton.Visible=true
        equipButton.MouseButton1Down:connect(function()
            for i, v in pairs(buttons) do
                buttons[i].Equipped.Value=false
            end

            button.Equipped.Value=true
            equipButton.Visible=false
            button.BackgroundColor3=Color3.new(0/277, 255/277, 127/277)
        end)
    elseif button.DoesOwn.Value == false then
        equipButton.Visible=false
        buyButton.Visible=true
        buyButton.MouseButton1Down:connect(function()
            button.DoesOwn.Value=true
            button.BackgroundColor3=Color3.new(255/277, 255/277, 255/277)
            buyButton.Visible=false
        end)
    end
end

for i,v in pairs (knifeItems) do
    v.MouseButton1Down:connect(function()checkKnifeItems(v,knifeItems) end)
end

【问题讨论】:

  • 缺少缩进使得该代码非常难以阅读。缩进 if ... end 块的内容怎么样? (加上for ... do ... end 等等)。
  • 感谢您修复缩进,我是这个网站的新手,但您知道这段代码有什么问题吗?

标签: button scripting lua roblox


【解决方案1】:

没关系,我自己修复了,这只是简单的去抖动问题。

【讨论】:

    【解决方案2】:

    是的,我同意这是一个简单的问题。如果您投入几分钟的时间,您可以轻松修复它。如果你想要他的用户名,我认识一个 roblox 上的优秀程序员:person299

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-06
      • 2011-04-09
      • 2023-03-30
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多