Forum




Variable
8 replies



If you need local you need function initArray
If you want a local variable (which you should want 99% of the time), just put the local keyword in front of the first declaration of your variable. It will then be accessible only from within the current function (or script, in case you declare a local variable outside a function). You should actually always use local variables, either within your script or within your function, to prevent collisions.
example:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
addhook("second", "counter") local c = 0 -- the local variable c can be accessed from anywhere within this script, but not from inside another script. function counter() 	c = c + 1 -- This uses the 'local' variable c as declared above. 	print(c .. " seconds have expired since the execution of this little script") end
You looking for variable for all players (32), or something other?

Or if you want to read about the different variables that exist in Lua scripting, click the link below.

Quote
That would mean that b is a global variable as used in this code. Yay me? I'm getting better at Lua, I think. Anyways, the code above will print the global variable b as nil when the function is being called. Variables are assumed to be global unless explicitly declared local
1
2
3
4
2
3
4
function code() 	b = nil 	print(b) end

A local variable is as defined below by using the above code as template but with a slight difference.
1
2
3
4
2
3
4
function code() 	local b = nil 	print(b) end



