This shows you the differences between the selected revision and the current
version of the page.
wmebook:ch2 2008/01/10 11:41 | wmebook:ch2 2008/07/21 19:47 current | ||
---|---|---|---|
Line 103: | Line 103: | ||
</code> | </code> | ||
- | **file test1.script** | + | **file test2.script** |
<code script> | <code script> | ||
global a = a + 1; | global a = a + 1; | ||
Line 193: | Line 193: | ||
I think you’re getting a bit tired of this //variable// talk so we’ll focus now on different things and return to the big strength called **objects** a tad bit later on. | I think you’re getting a bit tired of this //variable// talk so we’ll focus now on different things and return to the big strength called **objects** a tad bit later on. | ||
+ | |||
====== 2.2 Conditions ====== | ====== 2.2 Conditions ====== | ||
Line 260: | Line 261: | ||
**if ( (a>1 && a<10) || (b =="John") )** is one of the more complicated tests. It will execute the following command if the variable //a// is bigger than 1 AND smaller than 10 OR if variable //b// contains the word John. | **if ( (a>1 && a<10) || (b =="John") )** is one of the more complicated tests. It will execute the following command if the variable //a// is bigger than 1 AND smaller than 10 OR if variable //b// contains the word John. | ||
- | //**Syntax rule no.4** | + | //**Syntax rule no.5** |
If you want to execute multiple commands in the condition, you use **curly** brackets to enclose the commands which will then take place. | If you want to execute multiple commands in the condition, you use **curly** brackets to enclose the commands which will then take place. | ||
Example:// | Example:// | ||
Line 381: | Line 382: | ||
Those loops are very nice for some background processes you need to carry on for the whole game. For example you can check if the background music is playing and if it stops, you can play another song from the play list or in the demo project those processes handle caption displaying. | Those loops are very nice for some background processes you need to carry on for the whole game. For example you can check if the background music is playing and if it stops, you can play another song from the play list or in the demo project those processes handle caption displaying. | ||
+ | |||
Line 445: | Line 447: | ||
</code> | </code> | ||
- | //**Syntax rule no. 5** | + | //**Syntax rule no. 6** |
function name must contain only alphanumeric characters and there shouldn't be any whitespace characters.// | function name must contain only alphanumeric characters and there shouldn't be any whitespace characters.// | ||
Everything should be very clear at this point. If it’s not, please review the previous chapters before you can understand what’s going on. The only important thing is that we passed to **if** command, instead of our good old direct comparison, a //function//, which returns true or false. **if** command evaluates the function (which in this case returns //false//) and then executes the //else// block. | Everything should be very clear at this point. If it’s not, please review the previous chapters before you can understand what’s going on. The only important thing is that we passed to **if** command, instead of our good old direct comparison, a //function//, which returns true or false. **if** command evaluates the function (which in this case returns //false//) and then executes the //else// block. | ||
+ | |||
====== 2.5. Includes ====== | ====== 2.5. Includes ====== | ||
Line 462: | Line 465: | ||
**Important:** | **Important:** | ||
Never initialize your variables in the include files. They will get reinitialized with every inclusion of your script. | Never initialize your variables in the include files. They will get reinitialized with every inclusion of your script. | ||
- | |||
- | <code script> | ||
- | for (var a=0; a<10;a=a+1) Game.Msg("Hell"); | ||
- | Game.Msg("1"); | ||
- | for (a=0; a<10;a=a+1) Game.Msg("Hell"); // note that I had to put the var away as it was already declared before. | ||
- | Game.Msg("2"); | ||
- | for (a=0; a<10;a=a+1) Game.Msg("Hell"); // note that I had to put the var away as it was already declared before. | ||
- | Game.Msg("3"); | ||
- | </code> | ||
====== 2.6. Objects ====== | ====== 2.6. Objects ====== | ||
- | Last chapter is dedicated to very cool part of WME scripting language – objects. | + | Last chapter is dedicated to the very cool part of WME scripting language – objects. |
We’ll start slowly with the following thought. Imagine that you have some real world object. Let’s say a table. Now the term table is pretty abstract - It can be made out of plastic, wood, metal or whatever, it can have many colors, it can be expensive or cheap. Wouldn’t it be nice to have all information about such a table together? | We’ll start slowly with the following thought. Imagine that you have some real world object. Let’s say a table. Now the term table is pretty abstract - It can be made out of plastic, wood, metal or whatever, it can have many colors, it can be expensive or cheap. Wouldn’t it be nice to have all information about such a table together? | ||
Line 551: | Line 545: | ||
</code> | </code> | ||
- | I think that this should be enough to get you started with scripting. The rest is just an application of what you’d just learned. I’m sure that you’ll have no problems understanding what’s going on now. | + | I think that this should be enough to get you started with scripting. The rest is just an application of what you have just learned. I’m sure that you’ll have no problems understanding what’s going on now. |