Jump to content

Call function from another resources


Hiding

Recommended Posts

Hello, how to call a function from another resources, for example I have a resource called "one-resource", which contains a function called firstFunction(). How do I get access to this function from the other resource called "second-resource"?

Link to comment

in the resource with the function u need to add the function to the exports in meta.xml

<export function="firstFunction" type="server" />

in the second resource use the call function to access the exported function

local oneResource = getResourceFromName("one-resource")
local result = call(oneResource, "firstFunction", arg1, arg2, ...)

just make sure one resource is running before calling its functions from second resource

  • Like 1
Link to comment

in the one-resource add to meta
 

<export function="firstFunction" type="server"/> <!-- if function on server side -->
<export function="firstFunction" type="client"/> <!-- if function on client side -->
<export function="firstFunction" type="shared"/> <!-- if function can used on server and client side -->

and in two-resource use

exports["one-resource"]:firstFunction( [args] )
-- or
exports.one-resource:firstFunction( [args] )


 

Edited by AngelAlpha
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...