Jump to content

What is the difference between these?


Recommended Posts

local variables have a scope limited to the block where they are declared (such as script files, functions, if statements, loops, etc).

so outside of that block they are either nil or have some other value if defined.

and testVar = "helo" will be a "global" variable for all script files in a resource (separated only by server/client side).

some examples:

  
local a = "one" -- variable is local to the script file 
b = "banana" -- variable is global for the resource 
  
outputChatBox(a) -- a is "one" 
if true then 
  local a = "two" -- adding local a variable inside "if" block 
  local c = "bleh" -- and some othe local variable 
  outputChatBox(a) -- now this a is "two" 
  outputChatBox(c) -- "bleh" 
end 
outputChatBox(a) -- outside that "if" block a is still "one" 
outputChatBox(c) -- and c is nil 
  
-- in some other same-side script file in the same resource: 
outputChatBox(a) -- nil 
outputChatBox(b) -- "banana" 
  

Link to comment
local variables have a scope limited to the block where they are declared (such as script files, functions, if statements, loops, etc).

so outside of that block they are either nil or have some other value if defined.

and testVar = "helo" will be a "global" variable for all script files in a resource (separated only by server/client side).

some examples:

  
local a = "one" -- variable is local to the script file 
b = "banana" -- variable is global for the resource 
  
outputChatBox(a) -- a is "one" 
if true then 
  local a = "two" -- adding local a variable inside "if" block 
  local c = "bleh" -- and some othe local variable 
  outputChatBox(a) -- now this a is "two" 
  outputChatBox(c) -- "bleh" 
end 
outputChatBox(a) -- outside that "if" block a is still "one" 
outputChatBox(c) -- and c is nil 
  
-- in some other same-side script file in the same resource: 
outputChatBox(a) -- nil 
outputChatBox(b) -- "banana" 
  

WOW! Thanks man. Now i know exactly what those things do! 8) Thanks ! :mrgreen:

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...