I want to add something to my game where users can create layouts and publish them into a datastore for any other players to load and play them.
The problem is that I want to add a search box where players can look up a layout by name (or possibly tags) and I am unsure how to go about searching through a datastore that wouldnt be ordered by anything.
Take Catalog Avatar Creator for example, where you can publish and look up community outfits. How would I make something like that?
I guess you could have an ordered datastore that shows layouts ordered based on UserID (almost random) that would correspond to data in a normal datastore.
Ex:
local orderedDataStore = DataStoreService:GetDataStore("InsertName")
local dataStore = DataStoreService:GetDataStore("InsertName")
local pages = orderedDataStore:GetSortedAsync("Layouts")
local page = pages:GetCurrentPage()
local layoutNames
for userID, layoutNameEncoded in page do
local layoutName = string.char(layoutNameEncoded)
end
-- Now you could loop through layout names and get the actual layout data
for _, layoutName in layoutNames do
-- Get data here from datastore
end
-- For adding new layouts you would do
local layoutNameEncoded = ""
for _, letter in string.split(layoutName, "") do
layoutNameEncoded ..= string.byte(letter)
end
orderedDataStore:SetAsync(userID, layoutNameEncoded)
dataStore:SetAsync(userID, layoutData)
I guess this would be difficult with a lot of layouts in the search since you would have to retrieve a lot of data.
There’s also a bunch of errors in this code especially in the encoding but I don’t have time to fix them.
This is a random idea for this that popped into my head.
There is one Datastore called Keys with ofc saves a table you can loop though all of that table, the key is random id and the value is a table with the creators userid and map name and when they search for a certain map all of the maps with that name are displayed. To load that map the id of map is saved as a key in a Datastore and load as you would.