GenericDeveloper Posted May 30, 2021 Share Posted May 30, 2021 I am trying to create an array which references exported variables from another resource however it seems that the call to the function is actually invoked rather than being saved as a reference to the variable. -- Array of functions we want to have a reference to, includes exported functions from other resources. local myFunctions = { ["FUNCTION_1"] = exports.myresource:myFunction, ["FUNCTION_2"] = exports.myresource:anotherFunction, ["FUNCTION_3"] = getElementPosition, ["FUNCTION_4"] = exports.myresource:finalFunction, } function executeFunctions(functionList, parameter) for i, func in ipairs(functionList) do -- For every function we need to call. functionToInvoke = myFunctions[func] -- Get the function reference from our array. functionToInvoke(parameter) -- Invoke the function and pass the parameter into it. end end executeFunctions({"FUNCTION_1", "FUNCTION_4"}, "some parameter value") -- Call executeFunctions() to recursively execute function 1 and 4 with our parameter. While myFunctions["FUNCTION_3"] works and references the native getElementPosition function, the references to exported functions don't work. Is this possible at all? Link to comment
GenericDeveloper Posted May 31, 2021 Author Share Posted May 31, 2021 (edited) 6 hours ago, GenericDeveloper said: I am trying to create an array which references exported variables from another resource Correction, this should say exported functions from another resource, not variables! Edited May 31, 2021 by GenericDeveloper Link to comment
Moderators IIYAMA Posted May 31, 2021 Moderators Share Posted May 31, 2021 3 hours ago, GenericDeveloper said: Correction, this should say exported functions from another resource, not variables! Try this local myFunctions = { ["FUNCTION_1"] = function (...) return exports.myresource:myFunction(...) end } Predefining export functions from another resource is not a good idea. Because when restarting that resource, all export functions will be reset. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now