DarkLink Posted June 17, 2011 Share Posted June 17, 2011 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
Castillo Posted June 17, 2011 Share Posted June 17, 2011 Yes, if i'm right you can use global variables from a file in another (in the same resource of course). Link to comment
DarkLink Posted June 17, 2011 Author Share Posted June 17, 2011 Hm ok, and dont need to use any function to call it ? just use it with his name.. ? like it was in the same file? thanks for ur answer Link to comment
Aibo Posted June 17, 2011 Share Posted June 17, 2011 every .lua file in a resource is also a code block, that can have it's local variables. any variable that is not "local" in this code block is accessible in other .lua files (in the same resource). viewtopic.php?f=91&t=33520 Link to comment
DarkLink Posted June 17, 2011 Author Share Posted June 17, 2011 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 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
DiSaMe Posted June 17, 2011 Share Posted June 17, 2011 Yes, variables aren't synced between server and clients, so variables set in the server won't be visible for client and vice-versa. Link to comment
DarkLink Posted June 17, 2011 Author Share Posted June 17, 2011 Thats what I was wondering eheh thanks alot guys . cya Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now