C-Script Tutorial for Beginners
From GameStudio Wiki
Note: This Tutorial is a translation of the German C-script tutorial. Some of the grammer may be hard to understand as it was directly translated into English for other Wiki users to read.
Introduction
Hello
They have already perused hundreds of Tutorials and, nevertheless, you get not to write it simply to own Scripte? They can do, actually, still no C script and want to learn it entirely? In both cases you are right with these Tutorials here. I hope that this Tutorial helps you and you are able to handle with the manual and to write your own Script after reading it. As all first one you should procure for yourselves a good Script editor. For users of the A6 I recommend SED (in the 3D Gamestudio folder). For users of A5 there is many different Script editors, how GST Builder or Wdledit. Best of all once on the download side from 3D Gamestudio (http: // www.3dgamestudio.de) look.
Have fun, TripleX
The beginning - comments
2. We want to start comments in this Tutorial comments. Comments comment as the name already says, her Script. If you her first more difficult Script to use ten.
Variables
Variables are a very important subject in the play development and in almost any other Scriptsprache. Variables are place holders for figures. That is the fact that you do nothing else as figures to substitute. This has the following advantages:
A variable can have almost every name THEY want. This proves a substantially better legibility and intelligibilit of the Scripts.
If we take to you have a weapon system with 20 weapons with which every weapon heats up with every shot about 1 degree. Now you position yourselves before you want to substitute for 1 degree with 1.5 degrees. Now you must change if you figures instead of variable 20 figures from 1 to 1.5 have taken. If you a variable take simply change the value with the Variable definition.
One defines variables as follows:
var name = worth;
A Variable definition begins always with the headword "var". Then the name comes for the variable. About this name one can change the variables and use. "Name" can be any name of your choice. As the last the variable is still assigned about the allocation operator = the value of your choice. They can define, by the way, a variable also without allocation. In this case the variable has the value 0.
var name;
Completely at the end there comes one more semicolon. Semicolons must be put to the end of every instruction, so that the engine knows that the order is to an end. If one a semicolon forgets it often comes to sequence errors what entails that the engine to you spits out 1000 of mistakes although you only 1 mistake have done.
[edit]
Basic arithmetical operations with variables
After we in the last chapter have learned to initialize variables, now we must still learn like one with them counts. Among the rest, in C-Script one can use 4 basic arithmetical operations operators (plus), - (below), / (divided), * (sometimes), as mathematical functions. Here some easy code examples:
Var a = 5; Var b = 2; // Definition from two variables
Here signified you learn Function main ()/*Was this in the next chapter. Look till then only the Variabelenveränderungen. */{a = a b; now // a is 7 b = a*b; now // n is 14 (7 times 2) b = 2; now // b the value 2 is simply given about = b = b;/*diese line signifies same like b = b b; */a - = b; // a = 7-4 = 3}
The comments should explain most. It is important still, that these lines...
a = b; a-= b; a / = b; a * = b;
... completely the same one signifies like the following lines:
a = a b; a = a - b; a = a / b; a = a * b;
One sees such abbreviations in computer languages frequent (programmers are quite decayed).
English Translation Incomplete - We apologise for the inconvenience.
