Getting Started #2: Lets code already Author: Xetrov Welcome to my 2nd tutorial. T his tutorial is: Getting started #2: "Lets code already" Yes. Lets code. Well, before we do, there are lots of things i gotta tell you, which I missed out last time. Probably because they are more relevant in this tutorial. As a note, most of this knowledge was gained from the old forums over at http://forums.planettribes.com , and some of the syntax etc has been learnt from the T2Faq by Bryan Helmkamp. This tutorial is still a work in progress, so as I think of other points, I will add them here. 1) Console Logging: Look for the following lines of code in "console_start.cs" located in your tribes2\gamedata folder: else if ( $arg $= "-mod" && $hasNextArg ) { setModPaths( $nextArg ); $i += 2; } and change it to: else if ( $arg $= "-mod" && $hasNextArg ) { setModPaths( $nextArg ); $i += 2; setLogMode(1); } This will log a sessions console messages to a log, if you run tribes 2 with the -mod parameter (eg, you run a mod). If you didn't want it to log ALL mods, you could change it to: else if ( $arg $= "-mod" && $hasNextArg ) { setModPaths( $nextArg ); $i += 2; if($nextArg $= "mymod"){ setLogMode(1); } } 2) Scripts: Now for the fun stuff. The code!!! I told you what tools you need to code in "Getting Started", and about the script(.cs) files. So things I neglected to mention: Script files are used by Tribes to determine Gameplay, Objects in the game eg Players, Weapons, Vehicles, Inventory stations etc, and how all of these things interact. Tribes 2 scripts are their own language, however they follow the syntax of C/C++. They are automatically compiled before the game is run into .dso files, making the scripts faster, and secure. Because Tribes 2 scripts are their own language, there is no documentation yet. There is only tutorials and faq's such as this and those that can be found at Bryan's site here . But experience in other Object Oriented Languages such as C++ will certainly help you in understanding Tribes2 coding. Function lists can also be found at Bryans site and also at the depot The code is broken up into lots of different script files. In these files, you will find functions, variables and other types of stuff common to Object Oriented Languages. If you have no idea what a function is, or a variable, I suggest you go and get started coding on some other language, and forget Tribes 2 Coding for a while. Datablocks: The "datablock" is like C's "class", in a way. They are where all information is stored, information about players, weapons, joystick effects, sounds etc. Most datablocks that you use are more like inherited datablocks, but more about that later! Datablocks are defined like: datablock ClassName(Name){ }; As mentioned above, datablocks store information. This information is stored in variables. These variables store anything, from what sound to play, to what model to load, to the force applied by a vehicles afterburners. (see variables below). But what data you can store in datablocks is define by ClassName. For ClassName = ItemData, you define data about an item (duh!). For ClassName = ParticleData you define data about particle effects. etc ;) An example datablock: datablock ItemData(MyPack){ className = Pack; catagory = "Pack"; shapefile = "pack_mypack.dts"; mass = 1; pickupRadius = 2; rotate = true; image="MyPackImage"; pickupName = "My Pack"; }; As you can see, there are lots of properties that are in the engine, which you can alter for your own datablocks. Dont worry about the stuff above, It was meant as an example of what sort of properties are available to a datablock. But do note the fact that each line(statement) ends with a semi-colon (;)! Functions: Functions are the real code in coding. Datablocks are just, as the name implies, blocks of data. Functions are where you take that data, and do stuff with it ;) There are a couple of different types of function. Though I'm not 100% sure what to call them, i'll call them Global functions, and member functions. Global functions are defined like: function functionname(%data1, %data2){ }; Member functions like: function MyPack::functionname(%data1, %data2, %client){ }; The major differences between these are: Global functions can only deal with data which is either Global, or has been passed to it(in %data 1 or %data2), whereas member functions can deal with any properties in its Parent(MyPack in the example above), global data, and/or the data that has been passed to it. Functions do not have to have any data passed to them. Or they can have lots. They dont have to be called %data1, %data2 etc. They could be called %var1, %beer, %natalieportman (you get the idea). But its not really a smart idea to starting calling variables completely unrelated things. Like if you pass client data to a function, it would be completely stupid to call that variable %friedrice (guess what I had for dinner tonight). One more thing: There are certain functions that are defined IN the engine. These you cannot change. Likewise there are certain functions that the engine looks for. EG: MyPack::onPickup. These functions are passed certain variables. If you mess with the onPickup function definition, and remove a variable that has to be passed, it aint gunna work! Example function: function MyPack::onDestroyed(%this, %obj, %prevState) { echo("MyPack destroyed by " @ %obj @ "!"); }; That function will be called by the engine when something destroys any MyPack object. What will happen when it does? It will print to the console "MyPack destroyed by Disc!" for example. (i think). Functions can also return data. Eg: function SayBlah(){ return "Blah"; } Should return the string "Blah". Returning values can be very useful. The way you use a returned value is like: echo "SayBlah returns the following :" @ SayBlah(); Inheritance: Now there is a scary word, if ever I heard one. It makes newbie programmers cringe in fear. Actually, it probably doens't. Maybe it was just me. What IS inheritance? Inheritance is what you do when you want to have something similar, or related to an existing object. Stupid example: A "dog" has several properties, common to all dogs. Eg it has eyes. It has 4 legs etc, and it can bark. A Beagle is still a dog(it has eyes and 4 legs and barks), but it has some more properties (it is short and fat ;) Example: datablock Dog { eyes = 2; legs = 4; }; function Dog::Bark() { echo("Woof Woof"); }; datablock Beagle : Dog { eyes = 2; legs = 4; color = "tri"; Name = "Zak"; }; function Beagle::Bark() { echo("Bow wow"); }; Yes. Well that was a stupid example ;) Notice how a Beagle is inherited from a dog (by the : sign). Notice how the Beagle has a color set to tri, a name, and it barks differently to normal dogs (my dog, Zak, is a tricolour beagle, and it barks differently to other dogs. Stupid dog). Are you thoroughly confused yet? I am, and I know all this stuff ;) Operators: Wow are operators important! You couldn't really do anything without operators. The following describes all of the operators: Operator(s) Description = Assignment Operator. eg x = 5; + - * / Arithmetic Operators: eg x = 5 + 2 - (3 / (8*4)); += -= *= /= Arithmetic Operators: eg: x += 5; This is the same as x = x + 5; (let x inrease by 5) ++ -- Increment/Decrement Operators: x++; x--; equivalent to x = x + 1. Putting the operator before x makes it increment x before it is used (eg if in a for loop), afterwards = afterwards. @ String Concatenation: eg x = "Hello " @ "World!"; Appends "World" to "Hello". == Equals to: eg x == 22; returns true if x is 22. Usually used in an if statement. eg if(x == 22) ... < > <= >= Inequality operators: eg x < 5; Returns true if x is less than 5(eg 4 or less) $= String Comparison: eg x $= "Hello World!"; Returns true if x is equal to the string "Hello World". && "And" Operator: eg x & & y; Returns true if both x is true and y is true; eg: if(x == 5 && y ==3)... returns true if both x==5 and y==3 || "Or" Operator: eg x || y; Returns true if either x is true and y is true; eg: if(x == 5 || y ==3)... returns true if x == 5 OR y == 3. ! "Not" Operator: eg x = !y; (If y = false, then x will = true, ie not false). x != y; Returns true if x does NOT equal y. ? : Ternary Operator: x < 5 ? x++ : x--; This is basically an if-then-else stuck into 1 line: if x < 5 then x++; else x--; That table might not have been super clear. If you have any problems, let me know in the forums and I'll spend some more time and fix it up! Conclusion I think that should do for 1 tutorial. I've spent a large part of my day doing this, so you'd better be thankful! In Getting started #3: (probably coming in a couple of days, I have university exams this week) Vectors & some other datatypes And I dunno. Gotta think about it some more. #4 should be adding a new basic weapon. That, ladies and gentlemen, is a wrap!