a = a + 1; ?!! :
This world wide syntax is known for programming.
Can you calculate a = a + 1 in math? No.
In scripting, yes you can.
It's really simple.
PHP Code:
function onCreated() {
a = 5;
a = a + 1;
echo(a);
}
Let's take a deep breath...
a is equals to 5, got it.
now a is equals to a + 1??
think of it this way, since a is equal to 5
then a is equals to 5 + 1
and a is now equals to 6.
And this indeed echoes 6.
What this does, is it adds x number to a.
(remember, it's better to use temp.a and this.a but in here I'm giving an example...)
PHP Code:
function onCreated() {
a = 5;
a = a - 1;
echo(a);
}
Same concept, will echo 4.
Now, it becomes really tiring for a developer to type a = a + 1; all the time, so there's another syntax you can use which is the following:
PHP Code:
// you can replace the number 1 by anything you want
a += 1; // Adds 1 to a
a -= 1; // Substracts 1 from a
a /= 1; // This means a = a / 1; which is a, this is done mostly by numbers other than 1
a *= 1; // This means a = a * 1; which is a, this is done mostly by numbers other than 1
a %= 1; // This one means a = a % 1; what % does it the remainder of the division. I'll explain this one later
a @= 1; // This one means a = a @ 1; Let's say a is noob, it will become noob1
a++; // smaller syntax for a = a + 1;
a--; // smaller syntax for a = a - 1;
So here's a small example:
PHP Code:
function onCreated() {
a = 3;
b = 5;
a++; // or a += 1;
b--; // or b -= 1;
if (a == b) {
echo(a + b);
}
}
And this will echo 8, because:
At the beginning, a is 3, b is 5.
We added 1 to a, it became 4
We subtracted 1 from b, it became 4
is a equals to b? Yes it is, then the script inside those curly brackets will run.
And it echoed 4 + 4 which is 8.
---
Congratulations, you now know the basics of Gs2!
If you have understood everything from this point, then you're good to go to my next thread tutorial, where I will be covering actual fun stuff like player interactions, player objects, loops and clientside!
If not, read it again and again and again, and ask all questions you have in this thread.
I'd be happy to answer.