How do you create a function for a table's path?

I’m looking for a way to syntax a path in a function. This is because the same path may be needed in some parts of the table, so ideally you would be able to return the path from a function.

The issue is that I don’t know how to write it down in a way the script understands.
The idea is this:

--The function
local function examplePath()
	
	return resultOfDescision = {
		
		print("printing")	
		
	},
	
end

--The main table
local leTable = {
	
	descision1 = {
		
		examplePath()
		
	},
	
}

You might consider the self keywords and metatables in this case for making this happen. Otherwise it’ll turn more rigid without them.

Also when examplePath() is executed without metatables, it should appearing more like:

local function examplePath()
    return {
        [key] = value, -- in this case, you might set keys to functions
    }
end

examplePath()[key]() 
-- the mapped function can be called, since the first execution
-- is referring to the table

It is still unclear what your objective is. Can you try concisely put the words more on it?

1 Like

Ok so I figured it out myself, but yours is probably more effecient (just a variable assignment it looks like).
I must have been writing the syntax wrong for returning the table, but now it is functional.

--The function
local function examplePath()
	
	local pathToReturn = { 
		
		Text = "resultText"	
		
	}
	
	return pathToReturn
	
end

--The main table
local leTable = {
	
	descision1 = {
		
		result = examplePath()
		
	},
	
}

print(leTable)
1 Like