Jump to content

Use function from another file in the script


SparkzZ

Recommended Posts

Posted (edited)

I have a script that contains 2 client files, let's assume they are called scriptClient1.lua and scriptClient2.lua

I created a function in scriptClient2.lua and want to use this function in scriptClient1.lua without exporting it in the meta..

is that possible ? and how ?

Edited by SparkzZ
Posted

No problem. If you want to use it in another script that is not defined in your scriptClient2.lua meta, you should use export:

<export function="functionName" type="client"/>

Hope you understand :)

Posted

If it's not local function and is on the same side then yes you can call it. same thing with variables because  every lua file in a resource is a code block, that can have it's local (variables/functions).  if it's not local in this code block it become accessible in other lua files in the same resource. Note:  local variables have a scope limited to the block where they are declared  so outside of that block they are either nil or have some other value if defined.

 

local function test() -- local function
local variable = "Hello" -- local variable
  
function test() -- Global function
variable = "Hello" -- Global variable

 

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...