DondoniniJoin Date: 2007-12-21 Post Count: 734 |
IDK what it does.
local Blah = "IDK WHAT LOCAL DO!!"
What does it do and what is the difference between using "local" and not using it?
Please answer and thanks if you do! :D
-=[ dondonini Productions ® ]=- |
|
DondoniniJoin Date: 2007-12-21 Post Count: 734 |
I think this has a lot of grammar mistakes. Don't talk about it please!
-=[ dondonini Productions ® ]=- |
|
|
local Blah = "IDK WHAT LOCAL DO!!"
print(Blah)
now it does something. |
|
|
local w = game.Workspace
means that in this script ONLY
the workspace can be refferred to by simply using w
a more practical, common use would be
local p = Instance.new("Part", game.Workspace) |
|
DondoniniJoin Date: 2007-12-21 Post Count: 734 |
@Theburnboss
Ummm... that doesn't tell what is the difference between using "local" and not using it.
-=[ dondonini Productions ® ]=- |
|
su8Join Date: 2009-03-06 Post Count: 6334 |
@pokelord910,
Are you sure, "in this script ONLY"..
Because aren't all variables in script only for that script usage :P? |
|
DondoniniJoin Date: 2007-12-21 Post Count: 734 |
I think I'm starting to get the idea. Thanks! :D
-=[ dondonini Productions ® ]=- |
|
|
No, no.
Local is for the function, loop, conditional etc. it's in.
function local()
local t="LOLHAX"
end
print(t)
Results in an error.
Nonlocal means it can be accessed by all things in the script.
function nonlocal()
t="LOLHAX"
end
print(t)
Prints "LOLHAX". |
|
DondoniniJoin Date: 2007-12-21 Post Count: 734 |
@BrandonFireflower
ooOOOOOOOOOooohhh!!!!! I GET IT NOW!!! Thanks!! :DD
-=[ dondonini Productions ® ]=- |
|
YioneeJoin Date: 2010-10-03 Post Count: 322 |
@ Brandon, creating a function with the name "local" has nothing to do with local and global variables.
@ dondonini, if you put "local" in front of a variable, that variable can only be accessed in the script that you assigned the variable in. If you don't use the word "local" then any script can see that variable. (I tried to word it simple as I could to help you understand) |
|
DondoniniJoin Date: 2007-12-21 Post Count: 734 |
@yionee
OK thanks! :D
-=[ dondonini Productions ® ]=- |
|
|
plus if you use local you can use the varible and change it later in the script
example
while true do
local text = ":D"
print(text)
wait(4)
local text = ":("
print(text)
end
with local you can chnage what the varible represents at any point in the script. |
|
SpectrumwJoin Date: 2009-08-04 Post Count: 13510 |
@Text
No. You can do that with any variable, that's the reason they are called 'variables'.
@OP
If you use 'local' when assigning a variable, that variable will only be avaliable in the specific snipet of code where it was created at. I.E;
if true then
local Var = 'Hello'
print(Var)
end
print(Var)
>Hello
>nil |
|
jav2612Join Date: 2010-06-14 Post Count: 1189 |
|
|
|
Well I for one use local in the instance that I deal with things outside the scripts parrent that can be generalized. Like kill scripts and regen buttons. Mostly kill script then I narrow it dow by adding a couple of bools and the ine would look like
script.Parent.Touched:connect(function(part)
-- All characters have a Humanoid object
-- If the model has one, it is a character
local h = part.Parent:findFirstChild("Humanoid") -- Find Humanoids in whatever touched this
|
|
PyzothonJoin Date: 2011-10-26 Post Count: 822 |
Local variables are accessed faster than normal variables, take up less space, and are generally used more often than global variables (which are the default variables). But, local variables only exist in there scope. A scope starts whenever you use the keywords do, if, and function.
local a = 5
if a == 5 then
local b = 10
print(b)
end
print(a)
print(b)
> 10
> 5
> nil
The third result is nil because the variable b's scope ended, thus making it unaccessable. The only reason it printed the first time is because you printed it inside its scope.
Pyzothon, novice scripter/programmer. |
|
AgentFirefoxTop 100 PosterJoin Date: 2008-06-20 Post Count: 22404 |
Local assigns the scope within the context of the given executable. |
|