Page 1 of 1

Am I Insane? Yes, probably...

Posted: Sun Apr 13, 2003 10:31 am
by Bjarne BZR
I'm working on a tutorial on scripting... yep, you read right :D
A basic tutorial on how to use the scripring language. It is based on the
Script Files.txt scripting language definition that is shipped with MOHRadiant. I just started it, so it is far from complete. But I would like some feedback on the tutorial to see if it is worth my time... does the beginners understand it? Do the veterans find anything wrong ( I dont want the first thing the beginners learn to be incorrect ) ?

So check it out in its current state: http://www.planetmedalofhonor.com/rjuka ... orial.html

Posted: Sun Apr 13, 2003 12:35 pm
by jv_map
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 :oops::
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).

Posted: Sun Apr 13, 2003 1:30 pm
by Bjarne BZR
Wow jv... you actually read it in detail :D Thanx!

I wrote the first part in the middle of the night, that should explain the nice errors you found :oops:

About the operator example; I guess I'm going to add a section on operator precedence, casting and type promotion later in the tutorial... beginners will NOT want to know about them from the start :wink:

Again: brilliant feedback!

Posted: Sun Apr 13, 2003 2:17 pm
by Ace of Spades
A tut on scripting....now this is definitely what we've all been waiting for! When it comes to scripting, I just look the other way! :lol: Thanks Bjarne for being so ambitious. This is I'm sure a lengthy task and the mapping community will owe you big time!

Hooray! Hooray! Bjarne will save the day!

Ace

:D

Posted: Sun Apr 13, 2003 2:34 pm
by Bjarne BZR
Easy now, I'm not there yet! ( But with cheers like that, you cant help but feeling a tad extra motivated :D )

Posted: Sun Apr 13, 2003 7:07 pm
by Faceball
All i can say if it's as easy to read and understand as your other tuts it should be great.

Thx for taking time to help make things easier for us newbs to learn. You and your efforts are appreciated more than you know. :D

I read what's there so far and it explains things nicely. Still not used to all the lingo but it does help explain more of what things do. :D

Question:

expr - expr Subtracts 2 expressions. Example 6- 2 results in the value 2

Should the result value be 4 not 2?

Posted: Sun Apr 13, 2003 7:18 pm
by Bjarne BZR
Faceball wrote:Question:
expr - expr Subtracts 2 expressions. Example 6- 2 results in the value 2
Should the result value be 4 not 2?
Make your own tutorial :wink: ( Just kidding )

You'r probably right ( Copy paste error )

Posted: Sun Apr 13, 2003 11:07 pm
by Bjarne BZR
I found something sttange when reading up on Arrays in the language definition:

Hash table arrays:
Unitialised entries evaluate to NIL. Any new entry can be set.

What is a Hash table array? How does it differ from other arrays? How do I make one?

Posted: Mon Apr 14, 2003 1:44 pm
by jv_map
Hmm good question, I don't think there's any difference. Maybe they meant some kind of 'nested' arrays with this:

local.a[1][1][1]
local.a[1][1][2]
local.a[1][2][1]
local.a[1][2][2]
.....

:?

Posted: Mon Apr 14, 2003 2:21 pm
by Bjarne BZR
Hmm, maby so...
Script Files.txt wrote:Types of arrays
---------------

1) Constant array
Created by expression of the form entry_1::entry_2::entry_3:: ... :: entry_n
Constant arrays start their indexing at 1.
Once created a constant array can not be changed but it can be read for its values.

2) Hash table array
Unitialised entries evaluate to NIL. Any new entry can be set.

3) Targetname array
Created by the $ targetname operator if more than one entity exists for that targetname.
For example, $player is an array if more than one player is in the game.
Targetname arrays start their indexing at 1.
It looks as if they consider an array whith another content as a different type of array... strange

Posted: Mon Apr 14, 2003 2:25 pm
by jv_map
I also don't think this is true:
Somebody wrote:Once created a constant array can not be changed but it can be read for its values.

Posted: Mon Apr 14, 2003 2:29 pm
by Bjarne BZR
Hope so, because one single general Array type is A LOT easier to explain... people have trouble enough getting their heads around ONE type of Array as it is :wink: