On syntax.
Syntax is the most important thing in any programming language, scripting language, any logical language ever.
Everything stays mostly the same across languages, the ONLY things that change are syntax and functions. SO! Let's get a little intro to syntax.
Lua is EXTREMELY SIMPLE. Fantastically simple! It's a wonderful language to learn.
Let's start with the first thing any intro to logic should start with. An IF statement.
Bam. That's it.
That's it. That simple. BUT! You're not quite done yet.
Code:
if x == y then
y = y + 1
end
Now, this is just a little bit harder. If x is the same as y, increase y by 1. In Lua, you can refer to a variable inside its own definition. Now, notice the equals. In the if line, there's two of them. That means that it CHECKS if x is the same as y; it's a "traditional" equals. So what does a single equals sign do? It SETS something. y = y + 1 means that Y is set to itself, but one higher. Continually increasing.
AND THE MOST IMPORTANT THING: end. You absolutely have to make sure to end any logical statement. Otherwise, everything after the then will be DONE, rather than checked or whatever you want to have happen.
And now for the SECOND most important thing: nesting.
What if I wanted to have something checked, and then if that's true, having something else constantly done?
Code:
if x ~= y then
while y < x then
y = y + 1
end
end
See how the while goes INSIDE the if? That's absolutely one of the most important things programmers need to learn to do, and even if Lua is a fairly limited scripting language, it's good to do it properly. It helps legibility (for both you and anyone else looking at your code), it helps debugging, and it just looks better.
This applies to ALL logical statements. If, while, for, and also for things like functions.
ENDS LESSON 1