generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Wat is local for?

Previous Thread :: Next Thread 
testdummy5000 is not online. testdummy5000
Joined: 04 Jun 2010
Total Posts: 818
21 Jul 2014 07:19 PM
My friend tells me that local before a variable tells Lua that you are declaring a variable. But it still works the same if you don't put the word local before you declare a variable...

EXAMPLE:

local var = 1
or
var = 1

what difference does it make, and what other scripts can I use it for. Please help! I tried searching on google but nothing really came up.
Report Abuse
HuntHello is not online. HuntHello
Joined: 19 Jan 2011
Total Posts: 577
21 Jul 2014 07:22 PM
if you declare a local variable its only available in the current scope.
Report Abuse
testdummy5000 is not online. testdummy5000
Joined: 04 Jun 2010
Total Posts: 818
21 Jul 2014 07:25 PM
current scope? Like the script only?
Report Abuse
HuntHello is not online. HuntHello
Joined: 19 Jan 2011
Total Posts: 577
21 Jul 2014 08:59 PM
hello, in the script:
local a = 1
print(a)
function hi()
print(a)
local b = 2
end
hi()
print(b)
, the output will be
1
1
nil
this is because declaring a local variable in a function will only work in the function, so variable b exists in the function, but not outside of it.
Report Abuse
HuntHello is not online. HuntHello
Joined: 19 Jan 2011
Total Posts: 577
21 Jul 2014 09:01 PM
for added reference, if you want a variable that can be referenced outside of the script (called a global function) take a look at _G variables, http://wiki.roblox.com/index.php?title=Global_function
Report Abuse
Xephyric is not online. Xephyric
Joined: 26 Mar 2009
Total Posts: 2270
21 Jul 2014 09:03 PM
if blah then
--this is a scope
end
if blah then
--this is another scope
end

if blah then
--this is a scope
if blah then
--this is a scope that derives from that one (and can use it's local variables)
end
Report Abuse
Xephyric is not online. Xephyric
Joined: 26 Mar 2009
Total Posts: 2270
21 Jul 2014 09:04 PM
forgot an end
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
21 Jul 2014 09:06 PM
a = true
do
local a = false
print(a)--false
end
print(a)--true

local variables can only be used inside their 'scope'
Report Abuse
testdummy5000 is not online. testdummy5000
Joined: 04 Jun 2010
Total Posts: 818
21 Jul 2014 09:30 PM
Thank you!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image