Jump to content

GenericDeveloper

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by GenericDeveloper

  1. Correction, this should say exported functions from another resource, not variables!
  2. 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?
  3. But how would you use call to get all of the exported functions? As far as I know, you can only use call for a specific export function call in which case I may aswell just write exports.myResource:functionName every time.
  4. A shame, the way I am currently doing it is with onClientResourceStart. I was hoping there might be a more efficient way to do it - guess I'll just have to continue adding an event handler in each file that makes use of this shorthand reference to a resource's exports.
  5. If I have a resource called 'theResource' and this resource has a few exported functions that I am using in another resource, you just call the exported function like this: local info = exports.theResource:getInfo("parameter") This calls the export as expected. To make this more convenient for cases where you need to call the resource many times such as using multiple exported functions, the reference to the resource's exported functions can be shortened down to: resource = exports.theResource -- Save the reference to all exported functions from the resource called 'theResource' local info = resource:getInfo("parameter") The problem however is if the resource called 'theResource' is ever restarted, all calls to any exports using the variable 'resource' no longer work since of course the existing reference to the resource root has changed as it was restarted. Now all the export calls do not work and throw errors. Is there a way to obtain the reference to the resource again, preferably without the use of event handlers?
×
×
  • Create New...