Dictionary functions help

I am making a cooking system where a UI tells you where to go. I tried to call functions from a table, but when I call pcall(foodTier["Cheese Pizza"][1]) it runs all the functions. Is there a better way to do this?

local foodTier={
	["Cheese Pizza"]={
		getPlate(),
		getFridge(food.Dough),
		getFridge(food.ColdCheesePizza),
		getHeat(food.CheesePizza)
	}
}

I’m not exactly sure, what you are trying to accomplish could you give more context?

Basicly, I want each sub table in foodTier (which there are going to be a lot of them) to be a set of 4 different functions that get called one by one, but whenever I try to call one function, it calls them all.

I don’t believe your approach here is correct, may I get more information on how the other functions work?

local function getFridge (item: Instance)
	step.Text="Go to the fridge"
	print("fridge")
end

local function getPlate()
	step.Text="Grab a plate"
	print("plate")
end

local function getHeat(item: Instance)
	step.Text="Go to the oven"
	print("oven")
end

Where step is a textlabel. It doesn’t print anything, but it changes the text to `“Go to the oven”


local foodTier={
	["Cheese Pizza"]={
		getPlate,
		getFridge,
		getFridge,
		getHeat,
	}
}

You have to remove the parentheses

1 Like

But he wants to send parameters.

I’ll just add them after the functions.

local function func1(test)
	print(test)
end

local foodTier={
	["Cheese Pizza"]={
		func1,
	}
}

pcall(foodTier["Cheese Pizza"][1], "Test Value")

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