Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What's the difference? I just started scripting so don't judge.

Asked by 2 years ago

What's the difference between

local Something = Something2 and Something = Something2

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
local something1 = something2

creates something called a local variable. That means that only the function, or part of code that this line is in can actually access this variable. This is really useful if you need to have a lot of variables that might have the same name but need to have different values

on the other hand, with no local,

something1 = something2

creates a variable that the entire script can access. That can be really useful if you want to store a value and use it again later somewhere else.

Ad
Log in to vote
0
Answered by
manith513 121
2 years ago
Edited 2 years ago

You cant have a variable = another variable that has no value. For example.

local Something = "nothing"

right now that variable equals the text "nothing"

I can do after that

local Something2 = "Something else"
Something2 = Something

What this does is make the new variable, Something2, equivalent to the first one. the value of Something2 is not "Something else" but the new value of it is "nothing" as that was the value of the first one.

I can do this vice versa as well by doing

Something = Something2

This will make the first variable something, the same value as the second variable. The new value for the first variable is "Something else". If both variables are already the same value, then interchanging them in between the = symbol doesn't do anything. However, whenever you put a = the thing you put before the = is the thing being changed, and what you put after the = is the value you are changing the first varible for. If this made sense, mark this as the answer.

0
Thank you, but that wasn't what I meant, at least a learned something new. hussinhd5 7 — 2y

Answer this question