Functions In Tables Ideas

Hello! I’m RazorBladedino117, and I have questions I’m hoping the community can answer. I currently have a build system, similar to fortnite’s, and I was thinking of a new idea to call on functions from a module, as each building piece, has a different way to calculate it’s position in my project.

Local Script
local CalculateModule = (blah blah)

— Later on in the script —
Blueprint = “Wall”
Module Script
local CalculateModule = (blah blah)
CalculateModule.FunctionTable ={[“Wall”] = function CalcWall(Blueprint) print(Blueprint) end}

function CalculateModule.FireCalc(Blueprint)
local Function = CalculateModule.FunctionTable[Blueprint]
return CalculateModule

Would this actually print out “Wall” ? Sorry for any typos, as I’m currently on mobile. Thanks for all the help!

Yes, that should work. Functions are first-class in Lua which means you can use them and pass them around as variables and values.

As a side note, three ` (not apostrophe or quote) are for code blocks.


Thanks for the suggestion! I’ll attempt to encorporate it into my progams now!