More efficient way of making an index?

Hello, I’m currently creating an index and I’m having no problems with it, However when it comes to saving and keeping track of what items a player has unlocked/hasn’t the only way I could of is having a boolean value for each item and saving if its true or false. This would work fine but with an index with possibly hundreds of items that may not be a great way so I was wondering if there was any other way for saving indexes that might be a little more efficient.

You could use two arrays, one representing unlocked items and the other representing locked items.

local locked = {"Apple", "Banana", "Pineapple"}
local unlocked = {"Pear", "Mango", "Orange"}

local function unlockItem(itemName)
    local index = table.find(locked, item) --get index of item from the locked array
    local item = table.remove(locked, index) --remove item from the locked array
    table.insert(unlocked, item) --add item to the unlocked array
end

unlockItem("Banana")
3 Likes

that’s actually genius thank you so much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.