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: Is 'local' a variable in a function?

Previous Thread :: Next Thread 
SethDusek5 is not online. SethDusek5
Joined: 26 Mar 2011
Total Posts: 2580
23 Apr 2013 07:07 AM
I am a bit confused, or is it just a variable.
Report Abuse
Voxility is not online. Voxility
Joined: 15 Apr 2013
Total Posts: 584
23 Apr 2013 07:33 AM
local means it stays in the object like in a function it won't go global. So lets say function a() local var = "asd" end print(var)

It outputs nil because var is a local value instead of global value.
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
23 Apr 2013 10:40 AM
[ Content Deleted ]
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 10:43 AM
local is mostly used (or what I use it for) for multiple copies of the same variables.
Like

for i = 1,10 do
local l=i
delay(1, function()
print(l)
end)
wait()
end

Without the local, it would just print 10 every time.

-={3137}=-
Report Abuse
Desperian is not online. Desperian
Joined: 07 Feb 2012
Total Posts: 3371
23 Apr 2013 11:05 AM
@Electro,
Without the local, it would still print 1-10.

e.e
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 11:07 AM
Nope.

for i = 1,10 do l=i delay(1, function() print(l) end) wait() end
Output;
10
10
10
10
10
10
10
10
10
10

-={3137}=-
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
23 Apr 2013 11:09 AM
Every "Block" has it's own "sphere" of 'local-ness'

A "Block" may be thought-of as anything inside an End.....

if true then
local a = 1
print(a)
end
print(a) -- a no longer exists.

Bite on that,
Bri
Report Abuse
Desperian is not online. Desperian
Joined: 07 Feb 2012
Total Posts: 3371
23 Apr 2013 11:09 AM
MKay, I was personally referring to the fact that that local variable was unneeded and you could simply do,

for i = 1,10 do
delay(1, function()
print(i)
end)
wait()
end
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 11:15 AM
I was using it as an example.

-={3137}=-
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