This is a
great initiative. I'm sure this will give beginning scripters much more insight on the language

. I'm glad someone finally took the effort to try making it all clear. Everything seems quite comprehendable to me at least, but I can't tell if someone who has never seen a script before will understand all of it.
I've got a few small remarks (always want to annoy you

):
45 - 12 * 3 / 5
Perhaps surprisingly, the game will think this equals 45. The error is in the 3 / 5 part: it's a division of two integers, so the game casts the entire value to an integer: 0. You have to cast either the 3 or the 5 to a float before. The easiest way to do this is by adding the floating point yourself:
45 - 12 * 3.0 / 5
level.targets_to_destroy = randomint(3) + 2
This will not create a value between 2 and 5 but one between 2 and 4

. The randomint can be read as int (randomfloat 3). Randomfloat 3 can be read as 3 * randomfloat 1. Randomfloat 1 returns any value from 0 up to 1
not inclusive, so the actual value 1.0 is never returned. This means 3.0 is never reached either, and randomint 3 returns 2 (!) as maximum value. Another minor thing is that the ( and ) are not needed here but won't harm anything.
Sorry about this one

:
Logical or, if one of the expressions is true ( 1 ): output 1, else 0
With this definition, if(1 || 1) would be false. A logical 'or' also returns '1' if both expressions are true.
This is my very personal view:
Code: Select all
if (expr) {
statement
...
statement
} else {
statement
...
statement
}
Ofcourse this 'code' is correct, but I think it's easier to understand if you write
Code: Select all
if (expr)
{
statement
...
statement
}
else
{
statement
...
statement
}
instead. This way it looks more organized so I think it's more tasty for people's brain to eat. And that's the whole purpose of your tut, right?
Code: Select all
local.time = 5
while ( time > 0 ) {
iprintlnbold_noloc local.time + " seconds remaining!"
wait 1
local.time = local.time - 1
}
Should be
Code: Select all
local.time = 5
while ( local.time > 0 ) {
iprintlnbold_noloc local.time + " seconds remaining!"
wait 1
local.time = local.time - 1
}
(with 'local.' before time)
Same error at the 'for' explanation.
Well I made a long story of it. I hope you don't get this wrong though. I fully applaud this new tutorial 8).