| Main Page | |||||
|
|
|||||
|
|
Return to lesson 1 | ||||
| Lesson 2: Understanding and interpreting scripts. Part1. | |||||
|
Comments. Last time we edited the amount of power players get on game start-up. We just changed a value and it worked (hopefully), but we didn't really realize what exactly we were doing. We didn't touch any of the other weird-looking and weird-sounding stuff in the script. Now let's learn some of this 'weird stuff' that you will have to deal with when working with WZ scripts. Open rules.slo file (you probably still remember that it is located in the warzone2100\multiplay\skirmish directory and that rules.slo and rules.vlo are 2 parts of the same script and that rules files are 'describing' some general game behavior or game rules). Ok, now look at the first line. On the first 7 lines you can see some text, written by Alex Lee, who was a part of the Original Pumpkin team (and as far as I know wrote most of the WZ scripts). This is not the actual script yet, this is just a small comment, written by Alex, the scripts begins after the comment. The game just ignores such comments. How does it know it is a comment and it has to ignore it? Very simple. Take a look at first 2 characters on each of the first 7 lines in the script. Do you see // ? This character combination is a starting point of a single-line comment. It is a single-line comment, because when the comment starts with // , it ends with the end of the line, no matter what you write after // , the comment is over when a new line starts (carriage-return character, which is invisible to us, indicates the end of the line). It always ends when the line ends, but it can start almost anywhere in the script, at the very beginning of the line, or after a command or a function. Let me visualize it for you.
Comments are very useful when working with scripts. You make comments to help yourself understand the script after maybe 1 year, Imagine you haven't worked with the script for a year, then you open it to update it, but it can be rather difficult to understand it, even if you wrote it and here is where comments come to help. They help you to understand what you were thinking when writing a particular part or line of the script. Apart from that you can use comments to visually divide your script into logical parts, for example take a look at the picture, do you see a //////////////////////////////////////// line? It is a comment line, even though there is no text, but first 2 characters (//) make this line a comment and this line helps navigating through large script files. You can't just insert a line like: ----------------------------------------------------------------------- because everything in the script is a command for Warzone, unless it is a comment, but ----------------------------- is not a comment, you have to make it a comment, like this: //---------------------------------------------------------------- Now it's a comment and WZ will not show a message saying that it can't understand the script, it will just ignore this line. And the final and maybe the most important purpose of comments is for deactivating some script parts. Do you remember in the last lesson we were editing this line: setPowerLevel(1300,playnum); What if we made this line a comment, like this: //setPowerLevel(1300,playnum); ? Then this line wouldn't exist for WZ, it would think that this is probably some text inserted by the scriptor and wouldn't pay attention to it and you won't get any power on game startup. Now there are many different maps, some are easy some are difficult and you might think that 5000 power units is too much for some maps, it is sometimes faster to use comments then to edit the value every time. What if you had 3 versions of this line and only 1 would be enabled at a time, depending on the settings you choose in WZ, like this: setPowerLevel(1300,playnum); //Original WZ setting //setPowerLevel(5000,playnum); //For difficult maps //setPowerLevel(500,playnum); //For easy maps Only the first line is currently 'active' and is a part of the script. If you want to play on a difficult map, you just comment-out the first line and remove the comments from the second line and the second line becomes part of the script. The second comment on the second line stays a comment, because of //. You can have as many // in the comment as you want, only first 2 // characters are important, WZ just skips all following text until the end of the line. Now imagine you have a big part of script that you sometimes want to deactivate or activate. It would take too much time putting // on the beginning of each line and then removing them. For this purpose there's a so called multi-line comment. It starts with /* and ends with */. Everything between /* and */ is skipped by WZ, no matter where /* and */ are located. You can put /* and the beginning of the script and */ at the end of the script and deactivate the entire script this way.
Declaration Keywords. Now you know why there are // and /* */ in the scripts and what they do. But there are many more characters and words you still are not familiar with. Again, let's take rules.slo as our example. Open it (make sure it is original 1.10 rules file). Right under the comments, at the 9th line the actual script starts. Take a look at the first line: public STRUCTURESTAT command; What does it mean? If you search through the script, you will see that command is user later on in the script. Command is a variable of type STRUCTURESTAT and this line is a variable declaration. It's like saying "Let the word 'command' be a public variable of type STRUCTURESTAT". Why of type STRUCTURESTAT? STRUCTURESTAT is any structure type, like "Command center", "Factory", "Power generator", it just narrows the usage of the variable, it's not a number, not a unit, it command is a structure type. The first word in this line, public, means that this variable (command) is also mentioned in the corresponding .vlo file. It is public, it doesn't not only belongs to the .slo file, as opposite from private. Public is like telling WZ "go look in the .vlo file for more information on this variable", because this command variable uses some resources from outside of the script, it points to the "Command Center" which exists as a model somewhere in WZ resource files. And private would mean that the variable belongs only to the .slo file. Now open rules.vlo file and search for "command", you will find it at the 14th line: command STRUCTURESTAT "A0CommandCentre" A0CommandCentre is a normal command center you use when playing WZ games, this is how WZ calls it. So whenever there's command variable used in WZ script, it actually means that something is done with the "command center" type of structure. For example rules.slo file enables this type of structure for all players when the game starts, it doesn't do anything with a particular command center which is in your base, it does something with this type of structure, because command was declared as STRUCTURESTAT variable (and not STRUCTURE). This is a rather difficult example for beginners, but you will see that you will not have to deal with public variables very often. Now we know what all 3 words mean in a variable declaration, let's take a look at one more variable declaration. This time let's open player0.slo file. Looks for this line: private INT count,count2,result,result2,tempx,tempy; Private means that the variable(s) that are declared only belong to the .slo file, they are not used in the corresponding .vlo file. The second word is variable type. In this case it's INT, which means Integer, or just a number. count,count2,result,result2,tempx,tempy are all variables with same properties (private, INT), that's why they are all declared on one line, separated by commas. It is faster to declare many variables at once. The line ends with a semicolon, which tells WZ that there are no other variables. It's like full stop (.), we humans use to mark the end of the sentence. You will see some other variable types, they are all pretty simple to understand. TEMPLATE is a template you use to build a unit. BASEOBJ is any object in the game, it can be a tank, a cyborg, a structure, a VTOL, etc. FEATURE is more like a decoration of the map, used in WZ, it can a tree, oil resource, a stone, a destroyed bridge, it's also an object, but doesn't belong to anyone. RESEARCHSTAT is simply a research topic. DROID can be any unit on the map, a cyborg, a VTOL, a tank etc. BOOL is a boolean, this is a bit special, because many people don't understand what it is. It's not something that you can see in the game, it only exists to help you with scripting. For example, you have made a list of what to buy in the shop To buy: Vegetables Fish Chocolate and you leave some space for a checkmark near all the products you want to buy, so you could see what is already done when you look at the list. And the space for this checkmark you leave on the list, is what a boolean is. This boolean variable can have only 2 states, it can be either checked or not checked. When you deal with booleans you use TRUE or FALSE instead of Checked/Not Checked or Yes/No. When you buy fish, you set it's checkmark to TRUE, because when you look at the list you are orienting on the checkmarks. Next time when you will look at the list you will see that fish' checkmark is already TRUE (checked) and you won't buy any more fish. Now find this line in player0.slo file: private BOOL boolResult,boolResult2; There are 2 variables of type boolean: boolResult and boolResult2. Any of them can be TRUE or FALSE. When you declare them, they stay FALSE, until you set them to TRUE. You can also see boolean variables like flags, it is either set or not set, I think this is the concept Starcraft map editor used, main thing, it can only be TRUE or FALSE, nothing else. Another variable type, that you usually don't see in the game is GROUP. GROUP is just a group of units, for example 3 tanks and a cyborg. You declare a group variable, add some units to it using the script functions and then you can give a command to the group and all the units belonging to the group will execute the order. It's like selecting some units and pressing ctrl-1. You can then press 1 and give an order to the entire group. Some other stuff you have to know about variables: you have to declare variables before using them. You can't put a checkmark near 'vegetables' if you don't leave some space near it, that's why when you open a slo file first you see is a declaration of variables, that will be needed later in the script. Variables are placeholders for information. You can put your laptop in the case, but you can't put a car into it as well as you can assign 3 to an integer variable X, but you can't assign "Python Hover Medium Cannon" to it, because the placeholder for this information would be a TEMPLATE. You end each declaration with a semicolon ; Declaration can be more than 1 line long, only ; marks the end of the declaration, so that you can declare as many variables at a time as you want. Character case is always important in script important, if you declared your variable NumberOfUnits, you can't use numberOfUnits. You can't have spaces in variable names. SUMMARY. Ok, now let's test what we have learned, take a look at this line (I made it up, don't look for it in scripts), what does it tell us? private INT count,buildX,buildY,buildX2,buildY2; //declaration of variables of type integer (numbers) Private means these variables are only used in this slo file. INT means that these variables can only hold numbers (including negative numbers). The variables are divided with a comma. The declaration ends with a semicolon. 5 variables of type integer are declared. After the declaration, there's a comment, which starts with // and ends with the end of the line. May be continued: |
|||||