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 » Scripters
Home Search
 

What's the difference between these two?

Previous Thread :: Next Thread 
samueltacheisEpic is not online. samueltacheisEpic
Joined: 27 Feb 2014
Total Posts: 7
08 Nov 2016 04:24 PM
Sorry if this post made you cringe. I literally just started scripting a day ago.

Ok, so what's the difference between these two lines?

Part = game.Workspace.Baseplate

and

local Part = game.Workspace.Baseplate
Report Abuse
nooneisback is not online. nooneisback
Joined: 28 Feb 2012
Total Posts: 1672
08 Nov 2016 04:35 PM
Local variables exist only in the block they are in. For example:

Test = "global"
do
local Test = "local"
print(Test)
end
print(Test)

>local
global

Local variables are also often a bit faster.

If you set a global variable within a block, it will work as if you called it outside the block.

do
Test = "global"
end
print(Test)

>global
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Nov 2016 04:35 PM
Uh... I'm not quite sure what you're asking. Do you mean local or do you want to know what local is used for? I'll assume you want to know how it's used and what it is for.

Well..

Lets say you have this function and a overall number for starting but you don't want to change the starting number so you would do this:

pi = 3.14

function piplusnum()
local pi = input+pi--This variable only will exist inside of the function.
print(pi)
end

piplusnum(53)
print(pi)


Not the best way to show this but maybe you'll get the point?
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Nov 2016 04:36 PM
Ah. =]

function piplusnum(input)
Report Abuse
samueltacheisEpic is not online. samueltacheisEpic
Joined: 27 Feb 2014
Total Posts: 7
08 Nov 2016 04:45 PM
Ah ok I get it. Thanks!
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
08 Nov 2016 04:51 PM
global variables will be an index of the environment
local vars are faster and will stay within their scope

local _ENV = getfenv()

myVar = 2
local myOtherVar = 2

print(_ENV.myVar,_ENV.myOtherVar)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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