Difference between revisions of "EAX Theory Tutorials"
|Line 65:||Line 65:|
== Classes ==
== Classes ==
Latest revision as of 17:25, 16 August 2011
Welcome to the EAX theory tutorials. Those might not be the best tutorials ever, especially if you are completely new to programming, but they should give a good overview of what programming is like, and how it applies to the EAX language. Keep in mind that this is purely theory, thus, you might want to open up the EAX practical tutorials in another window, and have a look at it every time you want to apply what you have learned here.
I hope you know at least what a programming language is, else you should not even be here. But hey, just in case...
A programming language is a set of words (which we will call later keywords) and grammatical rules. Much like a real life language actually. Most programming language try to be human-readable, but of course, they never fully achieve this because if you haven't noticed, a computer is dumb, and is not able to understand anything else than series of 0s and 1s (also known as binary). If you want a language which can be easily translated into binary instructions for a computer to follow, it has to be relatively primitive, and not always very human readable.
Again, remember that a computer has no brain. I will do exactly what you tell it to do without even thinking about it. Any sign of intelligence is an illusion created by another program written by another human being. Basically, do not expect miracles from a script that you have written. If what you were expecting did not happen, you probably forgot to tell it to your computer (it's a god damn computer, not some alien thing with psychological abilities).
EAX is one of those many programming languages which are read from left to right, from the top to the bottom. It works by reading lines of code one after each other, and executing them. A line of code should always end with a semicolon ;, and thus, you can have several lines of code on the same line, and a line of code spread over several lines. If you ever encounter that, don't worry, it's only for human readability purposes.
You will also encounter lines which do not end with a semicolons, but those are exceptions that you will see later in this tutorial.
Variables are the base of almost every good programming language. Without variables, you have no memory, without memory, you don't have a notion of time, and you are unable to do complicated things efficiently.
A variable can be seen as a memory unit (or a box, pretty much), in which you put things which you can reuse later. Let's say you have to calculate something such as (12*9)+(12*9)*(12*9). The dumb approach would be to multiply 12 by 9, then calculate the same thing again, and again, which is what your program WILL do if you write a calculation like that. What you, as a human being, would do, is probably the most logical approach: calculate 12*9 only once, remember the result, and use it to do the rest of the calculation. Basically, you end up with 81+81*81.
Back to the box analogy... You can put a bunch of different things in a box, right? Well, a variable can contain a bunch of different types of values. In most programming languages, you will find numbers without decimals, and numbers with decimals. They are separated from each other for a rather simple reason: calculations without decimals are MUCH easier to perform, and will run a lot faster on a computer. Avoid using decimals when you don't need them.
In some programming languages, variables do not have a type. They can contain absolutely everything, and you can change their type at any time.
This is NOT the case of EAX, and you will have to remember it because you WILL get confused later if you don't. EAX variables are defined with a specific type, and once they are created, their type cannot be changed anymore. If you make a box which is meant to contain tomatoes, you can't put potatoes in there, even if you empty the box.
In EAX, there are two main ways to declare a variable. Those ways behave differently depending on the situation, you will understand that later when studying functions and classes.
type name_of_variable = value;
name_of_variable = type(value);
Where type is the name of the type of value that you want your variable to contain, name_of_variable is the name of the variable you want to create, and value is the value that you want your variable to contain.
The main variable types in EAX are the following:
int is an integer value, basically, a number without decimals.
float is a floating point value, or a number with decimals.
fixed is a fixed point value. It is also a number with decimals, which sacrifices flexibility for computing speed. Basically, you can do calculations with it about as quickly as with integers, but it has a lot of limitations. It was introduced in EAX because back then, when Worms Armageddon was released, computers did not have the amazing processors you might have now. As a result, a lot of operations in Worms Armageddon use fixed point values. But don't use those if you are not forced to, floating point values are far better.
bool is what people call a boolean value. It can contain only two different values: true and false. It's very useful for simulating logical things such as switches. A switch would be "true" if it's turned on, "false" if it's turned off.