|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 08 Nov 2016 04:36 PM |
Ah. =]
function piplusnum(input) |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|