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

What if a variable isn't defined?

Asked by 6 years ago
Edited 6 years ago

A friend of mine made a gun script, In his line of code I noticed that one of the variables doesn't have a value assigned to it (Character)

local Player     = Players.LocalPlayer
local Character 
local Mouse      = Player:GetMouse()

The script works, there's no doubt about that, but why? What does the character variable equal, and if it doesn't equal anything, why put it there in the first place?

0
you can assign a value to a variable later on INOOBE_YT 387 — 6y
0
So why didn't that person just declare the variable later on? DominousSyndicate 41 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Not assigning a value to variable within a statement makes that statement a Declaration statement, instead of a Initialization statement.

Declaring a variable just means you create a new variable that may or may not be used later on, and declaring it early means you can use it anywhere in the script as needed.

0
But to declare it you would have to use (Character =) right? So whats the point of doing it twice? DominousSyndicate 41 — 6y
0
Honestly there's not really a point but coding languages just have it :l hipenguinflip 30 — 6y
0
This is more for use in functions, loops, and proving something exists. hipenguinflip 30 — 6y
Ad

Answer this question