Jump to content

Global Variables


poncianux

Recommended Posts

Hey there, this is my first post.

I want to know if LUA can globalize variables through resources.

Example:

**You have one variable on a clientside/serverside resource called R1

wich contains his own meta.xml and one LUA file script.lua

In script.lua you have the next variable:

local XL3 = "Content" 
local LX10 = 0 

**You have other resource with the same description but name: R2

His LUA file named file.lua

In file.lua you want to use the variable "XL3" and "LX10" from R1 on R2

if (XL3 == "Content") then 
LX10 = 1 

++My point is simple, not so complicated like this, but want to know if in this script language is possible

On VB.net to use global variables you can declare them on a Module

On C# to use global variables you must call the variable from file and specify their use (rw)

Hope you can help me! Thanks

Link to comment

Better than element data: exports

You can use an exported function to return a variable.

local somevar = 1000000 
function getSomeVariable() 
     return somevar 
end 

And in the meta.xml just add:

Then call it like:

exports.resourceNameHere:getSomeVariable()

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