Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How in the world could i make a searchable GUI?

Asked by
BashGuy10 384 Moderation Voter
4 years ago

Alright, hello random people on the internet who are trying to steal my roblox account!

So my problem/concept is: How the heck can i make a searchable GUI. Because i decided to take one last attempt at making a sandbox tycoon, i wanted to add a searchable inventory/shop, how would i attempt this?

What i would guess to search a GUI would be, i would be using a text box fyi: if string.match(TextBox.Text, --[[I dont know what to put here]])

How could i make a searchable gui?

My current code (Client):

local building = require(game.ReplicatedStorage.Modules.Building)
local info = script.Parent.Info

local template = script.Parent.Template
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local classbuttons = script.Parent.Frame

local preview

local moveconnection
local move = function()

end

local removetemplate = function()

end

local addtemplate = function(object)
    local class = object:WaitForChild("Class")

    local newtemplate = template:Clone()

    newtemplate.Item.Value = object

    newtemplate.ImageTransparency = 0
    newtemplate.NameLabel.Text = object.NameString.Value
    newtemplate.NameLabel.TextTransparency = 0

    if class.Value == 1 then
        newtemplate.Parent = script.Parent.Folder.Building
    elseif class.Value == 2 then
        newtemplate.Parent = script.Parent.Folder.Decoration
    elseif class.Value == 3 then
        newtemplate.Parent = script.Parent.Folder.Money
    elseif class.Value == 4 then
        newtemplate.Parent = script.Parent.Folder.Worker
    end

    newtemplate.MouseButton1Click:Connect(function()
        print(object.Description.Value)

        script.Parent.CurrentObject.Value = object

        info.Description.Text = object.Description.Value
        info.Price.Text = object.Cost.Value
        info.ItemName.Text = object.NameString.Value
        info.ItemImage.Image = "rbxassetid://"..object.Image.Value
    end)
end

for i, v in pairs(classbuttons:GetChildren()) do
    if v:IsA("TextButton") then
        v.MouseButton1Click:Connect(function()
            local class = v.Class

            if class.Value == 1 then
                script.Parent.Folder.Building.Visible = true
                script.Parent.Folder.Decoration.Visible = false
                script.Parent.Folder.Money.Visible = false
                script.Parent.Folder.Worker.Visible = false
            elseif class.Value == 2 then
                script.Parent.Folder.Building.Visible = false
                script.Parent.Folder.Decoration.Visible = true
                script.Parent.Folder.Money.Visible = false
                script.Parent.Folder.Worker.Visible = false
            elseif class.Value == 3 then
                script.Parent.Folder.Building.Visible = false
                script.Parent.Folder.Decoration.Visible = false
                script.Parent.Folder.Money.Visible = true
                script.Parent.Folder.Worker.Visible = false
            elseif class.Value == 4 then
                script.Parent.Folder.Building.Visible = false
                script.Parent.Folder.Decoration.Visible = false
                script.Parent.Folder.Money.Visible = false
                script.Parent.Folder.Worker.Visible = true
            end
        end)
    end
end

for i, v in pairs(player.Inventory:GetChildren()) do
    if v:IsA("Folder") then
        local amount = v:WaitForChild("Amount")
        local object = v:WaitForChild("Object")
        local curamount = amount.Value

        amount:GetPropertyChangedSignal("Value"):Connect(function()
            local newamount = amount.Value
            if newamount > 0 then
                print(newamount.." "..curamount)

                curamount = newamount

                print("Curamount: "..curamount)

                addtemplate(object.Value)
            end
        end)
    end
end


2 answers

Log in to vote
0
Answered by
174gb 290 Moderation Voter
4 years ago

I did something like this, but I make it search for players in game.. maybe you can adapt my model to what you need, feel free to use

https://www.roblox.com/library/4140034927/Players-search

0
Thank you, ill look into this. BashGuy10 384 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Assuming you have a large amount of items to place, your best choice would be to use a binary search. What this does is that you start in the middle of the list and check if the value you're searching for is "less than" (since strings are obviously stored in binary, you can check if a string is less than or greater than another) or "greater than" the string in the middle of the list. If it's less than, repeat the steps for the values on the right of the middle of the list. Otherwise, use the values for the left of the middle of the list. This relies that the list is sorted, which you can do by using table.sort(list) You can also round list positions if you ever get a decimal.

To implement this with string searching, I'll assume the user typed in the start of an item, such as te and the items you have are better dropper dropper duplicator teleporter teleporter but better you'd write code to go to the middle of the list which is duplicator. In order to make it work with just the start of an object, you'd do ("duplicator"):find("te", nil, true) and the third argument makes it ignore string patterns and then check if it returned something and the first return value starts at 1. Since find didn't return a value and "duplicator" < "te" you'd go right. Then, you make your code repeat the process, and since ("teleporter"):find("te", nil, true) returns 1, 2, you get that value and look at the values near it (an index above and index below) and look for all the values that start with te. Then, you show these results on your UI.

Answer this question