I've been doing a lot of things like
[CODE]
local var = 1
local function varadd()
var = var + 1
end
print(var)
varadd()
print(var)
[/CODE]
And I was just wondering- doing var = something doesn't make the variable global, does it?
[editline]20th May 2015[/editline]
Also, I have many scripts creating and using MANY variables, so is there any way to check whether any variables created by a script aren't local to it? I have a feeling I forgot to put 'local' in front of a lot of stuff...
[url]https://github.com/wiox/gmod-global-finder/archive/master.zip[/url]
This can be used to find any functions that set global variables. Just install it as an addon and run a console-command like below. It does not find global variables set by a script's body, just functions within those scripts.
[code]
lua_variable_global_find lua
lua_variable_global_find addons/yourAddonName
lua_variable_global_find gamemodes/yourGamemode
...
[/code]
Example output:
[thumb]http://i.imgur.com/x1iqALw.png[/thumb]
The code in your first-post is correct.
[QUOTE=MPan1;47762128]I've been doing a lot of things like
And I was just wondering- doing var = something doesn't make the variable global, does it?
[/QUOTE]
No, lua see's your local variable and uses that instead of global.
Wow. Two great answers for both. Thanks guys, you're always amazingly helpful!
Sorry, you need to Log In to post a reply to this thread.