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: When to use local or not?

Previous Thread :: Next Thread 
Vampyroteuthiss is not online. Vampyroteuthiss
Joined: 17 Jun 2010
Total Posts: 11541
12 Nov 2013 04:59 PM
like local variables.

local x
local potato
local stufffs

THANKS OBAMA
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
12 Nov 2013 05:08 PM
When its constrained or open up a new scope, use local.

If you use a variable throughout the script, dont use local. Otherwise, its better to use local.

Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
12 Nov 2013 05:11 PM
Local variables are for a specific function. (If not specified within a function itself, then it's for the whole script and nothing but THAT script.)

Ex. 1 (Used in a function)

function example()
local cucumber = Workspace.Part --Now, this may only be used in this function.
cucumber.Name = "Cucumber"
end

example()

print(cucumber.Name) --This /should/ result in an error.

Ex. 2 (Used in the entire script)

local Apple = "Apple"
local Banana = "Banana" -- See? This wasn't specified in a certain function and may be used in this entire script, and can be used in multiple functions.
local Fruits = Workspace["Fruits"]


Am I wrong? Feel free to revise me. I'm a little rusty. ;b

~ ∂σи'т нαтє σи тнє ѕιggу ~
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
12 Nov 2013 05:23 PM
You're forgetting inside loops, conditional statements...

function potato()
local a = 1
while p == 2 do
local b = 2
if k == 13 then
local c = 3
print(a) print(b) print(c) -- all would run
end
print(a) print(b) print(c) -- c would error. outside scope
end
print(a) print(b) print(c) -- b and c would error. outside scope
end
print(a) print(b) print(c) -- all would error. outside scope
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
12 Nov 2013 05:23 PM
Obama should die.

or get "bloxed" To block the banner people.
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