Jump to content

Possible to acess global variables from another .lua file?


DarkLink

Recommended Posts

hello guys, lately I have used much of my time in Lua Scripting and MTA, and I must say that I am enjoying alot the experience.

All functions are in the wiki, and they all have a good tutorial on how to use them.

Today I had to read a bit of lua manual and learned a few more things, I must now say that the lua is a language that is very good that I did not know, the mere fact of not having to define types is very good!

I have been reading the section of the variables and found no answer to my problem, which is the following:

a local variable is only recognized within a scope (this is a function, an if / else / elseif, for, while) right?

on other side, a global variable is made by default, so for example "x = 5", is available anywhere in the file .lua, right?

My question is: is it possible to access a global variable from another file .lua?

Example Given:

engine.lua:

 y = true 
hello = 2 
  

and on lights.lua I want get the variable y which is declared as global in another file (in this case, engine.lua), it is possible?

Thanks in advance, awaiting response :)

Link to comment

I understand it now Aibo!! if I put local variable outside of any scope ( function/if/else/for/while..) the variable will be just for that file, if is on some scope will be for that scope only .

and if is global is for any .lua file of that resource :D

I get that thanks! but I still have ONE QUESTION bro.

you write this on the other topic: and testVar = "helo" will be a "global" variable for all script files in a resource (separated only by server/client side).

U tell that is separated by server/client side ?

I never understood that too.. a .lua file can have only function of the same side right ? .lua can only have client side functions or server side functions, not mixed? and if global variable is on client side functions file will only accessible for others client side functions file?

is that what u mean?

thanks!

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