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

Sorting game objects by value, is it even possible? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

Okay so I created a script that gets my Developer Products and copies the data into a frame so I can keep adding Dev products and the shop will update without me really doing anything. So the code to create these presets is this:

local scroller = script.Parent.scroller
local devProducts = game:GetService("MarketplaceService")

local products = devProducts:GetDeveloperProductsAsync():GetCurrentPage()
local market = game:GetService('MarketplaceService')

for _,v in pairs(products) do

    local cl = script.B1:Clone()
    cl.Parent = script.Parent.scroller

    cl.icon.Image = "rbxassetid://"..v.IconImageAssetId
    cl.Title.Text = v.Name
    cl.Name = v.Name

    cl.buy.MouseButton1Down:Connect(function()
        market:PromptProductPurchase(game.Players.LocalPlayer, v.ProductId)
    end)
end

The only problem is it's not in order of the 'gem amount' so it goes like 1000, 250, 750, 10000 any help with this?

The table layout is like this - local products = { ["random name roblox makes"] = { ["Name"] = "product1", ["PriceInRobux" = 100 } }

(that's not exactly it but I assume you understand.)

Basically I just want the frames to be ordered in Robux Price (which can be easily gained with v.PriceInRobux, it returns a string)

SOLVED (EDIT) This was solved by putting each dictionary into one table, and then using a custom table.sort function that checks the dictionary value PriceInRobux and then sorts them using that value. If anyone else has this problem here is the sorting function

Change PriceInRobux to the value you want to sort your dictionaries by

table.sort(sortedTables, function(a, b) return tonumber(a.PriceInRobux) < tonumber(b.PriceInRobux) end)
0
You could use a UIListLayout and name them based on their gem amount as an easy solution Vulkarin 581 — 5y
0
You can put the dev products in a dictionary and use table.sort Rare_tendo 3000 — 5y
0
^^ Probably better. I was going to say if you added them into a table then table.sort would sort them least to greatest numerically or you could add your own function to sort greatest to least etc ABK2017 406 — 5y
0
The problem with putting them in a table is, how would I then transfer that into the frames on the gui? User#16405 0 — 5y
View all comments (2 more)
1
Yeah I see how I would do it, I would put them into a sorted dictionary and then transfer that into the frames. Thanks I'll try it out tomorrow i'm not on my PC User#16405 0 — 5y
0
The dev products are dictionaries. They each contain their own special data so could you even put a dictionary into a dictionary, even if it was possible how would I then create the frames to hold that data. User#16405 0 — 5y

Answer this question