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

Can someone explain statements and variables to me?

Asked by 5 years ago

I know the basics of statments and varibles but i eant to understand them more could someone please explain them more please?

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

A variable is a way to declare something else. For example,

local myNumber = 10

This means whenever we say 'myNumber' anywhere in a script, it will actually mean '10' As an example

local myNumber = 10
print(myNumber)

This will put in the output section the number 10, because we said 'myNumber' is actually '10' So, in a more complicated example:

local myNumber = 10
if myNumber ~= 10 then
    print("Does not equal")
elseif myNumber == 10 then
    print("myNumber equals 10")
end

Not sure how much experience you have, but let's assume not much. The variable is there to represent something, in this case it is 10. The local behind it means it can only be used in that area/script. Then the if statement, basically the first if statement says 'if myNumber does not equal ten then' and then it prints 'Does not equal'

elseif takes over if the first statement/condition is not met. So if the variable myNumber does NOT equal 10, move to the next statement. This next statement (elseif myNumber == 10 then) basically says 'if myNumber equals 10 then print "myNumber equals 10"'

Now to declare an object/instance.

local part = game.Workspace.Bob

This basically is the same thing as above. We search in the 'Workspace' for an object named 'Bob' .. Now whenever you are talking about the object in Workspace called 'Bob,' you can just say 'part' instead of 'game.Workspace.Bob' With this, you can change properties as well. For example:

local part = script.Parent -- Assuming the script is inside the part, we say script.Parent to talk about the object above the script in the explorer.
while true do -- Loop
    wait(1) -- Wait 1 second
    part.BrickColor = BrickColor.new("Toothpaste") -- Change part color to 'Toothpaste'
end -- End lol

Then there's the end, pretty self-explanatory.

Need me to clarify? I'll be glad to answer any other questions you may have about this. This is one of my first answers so don't be surprised if it's bad. Thanks anyway.

0
what can else can i deare with variables? EzireBlueFlame 14 — 5y
0
Edited it, ^-^ xXDoneBeingCoolXx 33 — 5y
0
Do logical operators count as statements? Goulstem 8144 — 5y
0
Yes Leamir 3138 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

A statement is as its name suggests, an expression. And an expression is something that conveys meaning, in our context, it is conveying meaning through text. In other words, communicating to the computer, using Lua's syntax of writing code.

The code: if a > b then wait(2) end is what we call a conditional, as it takes a Boolean as an input. In other words it checks between two different states of formality, true and false. Which is itself a binary operation, as a Boolean can only work with one or the other.

Variables on the other hand are used as symbolic representations of expressions.

A variable means by definition, likeliness to change and adapt. This tells you a lot about variables already. Here's an example: words = 1+1 ...at first glance it looks like a not very useful component to scripting. However, they are one of the most important fundamentals, so that some programming tutorials in general, have it as the first thing you learn.

1 + 1 = 2 -- [Comment] the expression equates to 2

two = 2 -- [Comment] the word two also means 2.

You are simply holding the same present, but wrapping it in differently textured paper.

Answer this question