A really stupid question

I’ve been doing a lot of things like



local var = 1

local function varadd()
      var = var + 1
end

print(var)
varadd()
print(var)


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…

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.



lua_variable_global_find lua
lua_variable_global_find addons/yourAddonName
lua_variable_global_find gamemodes/yourGamemode
...


Example output:

The code in your first-post is correct.

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!