• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved QQ Revscript and Global var practice.

Status
Not open for further replies.

Codinablack

Dreamer
Content Editor
Joined
Dec 26, 2013
Messages
1,609
Solutions
11
Reaction score
835
Like the title says, its just a quick question.

Is it bad practice, or is there any reason one would want to avoid setting up a global variable in a revscript sctipt.

Like so:


Lua:
activeItemMap = {

    {spawn = 1285, firstDecay = 1286, lastDecay = 1287},

}

local global = GlobalEvent("ActiveSpawnItems")
global:interval(1000)
global:register()
 
Solution
I know the standard reasons to avoid global variables, I was just wondering if doing it in revscripts instead of thru the global.lua or lib folder was a big no no
It's fine, as long as it's outside of functions, so it's not constantly being refreshed.
The only benefit to it being inside of global.lua or lib folder, is so you can easily keep track of all your global variables in one place, instead of trying to remember where you put them all. xP
Unless you need to use it somewhere else outside of this script, then that's fine, but otherwise it is recommended to use local variables so as not to litter the global environment with garbage and that may cause confusion to other scripts at some point, although yes using fairly unique variable names is probably not too big of a problem, but it's a good practice to make everything local as much as possible

Local Variables and Blocks

It is worth mentioning that TFS can use LuaJIT and therefore it is a bit more optimized in all cases

In any case, performance would not be the main problem of creating global variables, but rather the fact of using global variables with names that are commonly used for libraries or constants, otherwise there is not much problem with it, you do not have much of to worry about this question
 
Last edited:
I know the standard reasons to avoid global variables, I was just wondering if doing it in revscripts instead of thru the global.lua or lib folder was a big no no
 
I know the standard reasons to avoid global variables, I was just wondering if doing it in revscripts instead of thru the global.lua or lib folder was a big no no
It's fine, as long as it's outside of functions, so it's not constantly being refreshed.
The only benefit to it being inside of global.lua or lib folder, is so you can easily keep track of all your global variables in one place, instead of trying to remember where you put them all. xP
 
Solution
I know the standard reasons to avoid global variables, I was just wondering if doing it in revscripts instead of thru the global.lua or lib folder was a big no no
Sorry, I didn't understand your question right, I guess!
but yes, as @Xikini said you can create global variables in the Revscript interface without any problem, however please use global.lua or lib/... If a variable is global it is because it will be used in different environments and you don't want the server to not find these variables at startup, since Revscript runs long after global.lua

You have to maintain a certain order so that later you do not have extra work for not being more orderly with the files and the declarations
 
The big problem I have with setting up global variables in global.lua or thru lib folder, is if there is any error in the file at all, then whole server is broken and players can't login simply because everything that should have loaded after the error won't, since it reads it all like one big file.


Loading different global variables inside revscript, like you said, comes long after the global.lua load, which means I can declare a global variable, and then if there is an error in that file, its just the one file that fails to load correctly, instead of everything.
 
It is simply a bad idea to modify a server when there are players online, for that you can test everything locally ;)
I agree. There should be a test server and a live server.
Do everything in the test environment, and replace the live server after internal testing.
 
It is simply a bad idea to modify a server when there are players online, for that you can test everything locally ;)

I agree. There should be a test server and a live server.
Do everything in the test environment, and replace the live server after internal testing.
If I did have a server hosted on a dedicated server, and did all my work locally... then the problem would still occur for MYSELF to be able to login to check something else I could be working on, or say I modified server source, and hadn't launched my "test" server since also modifying something in lua, but the lua part is easily fixed, and not of importance to me, in that moment, I just wanted to test something else, I would still be forced to resolve any issues with the lib simply to be able to login myself.

Please stop assuming things about me. It's starting to feel like im being condescended to.

At any rate this is solved , can we close thread please.
 
If I did have a server hosted on a dedicated server, and did all my work locally... then the problem would still occur for MYSELF to be able to login to check something else I could be working on, or say I modified server source, and hadn't launched my "test" server since also modifying something in lua, but the lua part is easily fixed, and not of importance to me, in that moment, I just wanted to test something else, I would still be forced to resolve any issues with the lib simply to be able to login myself.

Please stop assuming things about me. It's starting to feel like im being condescended to.

At any rate this is solved , can we close thread please.
We're just providing you with our knowledge and experience, not trying to be condescending.

Coding is an eternal battle of learning new things.

It took me a long time to accept that people's opinions are different from my own, and that there are people with more knowledge / experience then myself, regardless of whether or not I like them.

I'd say that Sarah and I are slightly at odds with one another and butt heads infrequently, but we still share in the knowledge that in some area's the other is more knowledgeable and we can learn from one another.

In the end it's up to yourself what information you want to absorb into your own coding practice.

--

That being said, I personally refuse to accept any errors or bugs in my code before continuing onto new projects.

They are certainly more annoying if they get in the way of logging in, as in your example, but that is rarely an issue and often easily fixed, since global tables / variables are almost exclusively static, and thus never change. So the error was something very recently added, and you are probably still working on it.

Once the global variable is fixed (usually just missing a comma, parantheses, or a mistyping) every other error would be inside a regular script, and wouldn't affect your ability to login. xP
 
Status
Not open for further replies.
Back
Top