Not much to explain but is there any way to make this more efficient? Each succeeding line is the same but with one added value. There ought to be a way to make this take up less lines and space. Is there?
local tier1Food = {'FrenchBread'} local tier2Food = {'FrenchBread', 'Muffin'} local tier3Food = {'FrenchBread', 'Muffin', 'Donut'} local tier4Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie'} local tier5Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel'} local tier6Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee'} local tier7Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin'} local tier8Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie'} local tier9Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant'} local tier10Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake'} local tier11Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake'} local tier12Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea'} local tier13Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake'} local tier14Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie'} local tier15Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie', 'BlueberryPie'} local tier16Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie', 'BlueberryPie', 'StrawberryPie'}
Hi Bunny,
local food_system = { foods = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie', 'BlueberryPie', 'StrawberryPie'}; tier_return = function(self, tier) local tab_to_return = {}; for i = 1, tier do tab_to_return[i] = self.foods[i]; end return tab_to_return; end } local tier_5_tab = food_system:tier_return(5); for _, food in next, tier_5_tab do print(food); end
Thanks,
Best regards,
~~ KingLoneCat
Regardless of your purpose, you should only use one table, containing all the foods in order.
From there, it depends on what you want to do.
If you absolutely need a table for each tier, then examine my function below called getTier. It returns whichever tier you want, given a number in range.
Since I am not sure what you are doing, I cannot necessarily give you more than that without shooting in the dark.
What the function does, is either gets the existing tierTable, or creates it based off the number you put into the function.
local Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie', 'BlueberryPie', 'StrawberryPie'} local tierTables = {} local function getTier(num) if num > 0 and num <= #Food then if tierTables[num] then return tieirTables[num] else tierTables[num] = {} for i = 1, num do tierTables[num][i] = Food[i] end return tierTables[num] end end end --Example usage, say I just wanted tier6 local tier6 = getTier(6)
If you have any questions let me know.
yes, but this is all you can do
local foods = { tier1Food = {'FrenchBread'}; -- use " ; " when putting tables in tables tier2Food = {'FrenchBread', 'Muffin'}; tier3Food = {'FrenchBread', 'Muffin', 'Donut'};{'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie'}; tier5Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel'}; tier6Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee'}; tier7Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin'}; tier8Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie'}; tier9Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant'}; tier10Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake'}; tier11Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake'}; tier12Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea'}; tier13Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake'}; tier14Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie'}; tier15Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie', 'BlueberryPie'}; tier16Food = {'FrenchBread', 'Muffin', 'Donut', 'ChocolateChipCookie', 'Bagel', 'Coffee', 'Muffin', 'ApplePie', 'Croissant', 'VanillaCake', 'Cupcake', 'Tea', 'ChocolateCake', 'PumpkinPie', 'BlueberryPie', 'StrawberryPie'} -- " ; " not needed on last line } -- to access these do --foods.tier1Food
I didn’t read through it all, but I’m just assuming there’s another item for each rank. This was typed on an iPad, so it might not work.
local food = { "food", "food2", "etc"} function GetAvaliableFood(rank) local foodAvaliable = {} for i=1, rank do table.insert(foodAvaliable, food[i]) end return foodAvaliable end