Author Topic: Tribes Coding Volume 1  (Read 9375 times)

0 Members and 1 Guest are viewing this topic.


  • Centurian Lord
  • ********
  • Posts: 2,691
  • Reputation: +0/-0
Tribes Coding Volume 1
« on: August 3, 2002 04:48 pm CDT »
Newbie Guide to Tribes Coding Volume 1

Welcome to the huge world of Tribes Coding. This guide will help you learn how to be a master. In this first volume, I will teach you the basics. If you already know the basics of Tribes code, then skip to the next volume.

Required files

I suggest getting pakscape from
You need a compresser and a decompresser to vol and devol the files

Brief History

Tribes code is more or less a twisted version of the C++ language. It carries all of the same traits, but it is easier to work with.

The Basics

If you have already looked at some of the code you may notice that it looks a little like algebra. Some things can be figured out like algebra, however, you MUST not think of it as algebra. You must also remember to use the {} brackets in functions and to end every line except a statement line with a ; at the end

In the code, there are 2 main things that almost run it all. They are called Global Variables and Local Variables.

Global Variables

Global variables can be placed anywhere outside a function and in any file. They start with the $ sign and usually have important information after it. Ex. ($Color = Red;).The whole point of a Global Variable is that it holds important data that can be accessed at any time. Now you may be asking this. Why worry about Local Variables if these Global Variables can do so much? Lets go find out.

Local Variables

Local Variables can only be places inside functions, and are probly the most important part to the code. They start with a % and are usually before any of the Script (long stuff that you won’t understand yet). Here is an example (%Color = Red;). As you may notice, The difference between a Local Variable and Global Variable seem to be only a $ and a $. One is inside a function and one is not. Local Variables are essential because is puts everything at ease to read and understand right next to each other. If you wanted to find a Global Variable, you would have to search all over the place. Global Variables can never be repeater, but Local Variables can be used as many times as you want as long as they are not repeated in the same function.


I have talked about function here and function there, but I haven’t really explained what a function is. All a function is, is a block of code that commands the game to do something when it is called from somewhere else. Still with me? Lets use a little example to show what I am talking about

function LocalSay()

When that function is called your play will say hi in a local area, meaning it won’t show up in box, but it will still play a sound near you.  Let me break this down to make it easier. the first word function which must ALWAYS be in lowercase tells Tribes that you want to do something. The words next to it “LocalSayâ€Â? Can pretty much be what you want them to as long as they are not spaced. Those are called the Function Names. With that in consideration, you should name them according to what you are putting inside. The () at the end is usually filled variables in some cases. In this case, you don’t need any variables inside, so we just leave it blank. Notice how this line doesn’t have a ; at the end? This is a statement line. I will talk more about this later. On the next line you have a { bracket. Anything between the { and } brackets will be included in the function. You must have them as they start and end the function block. The next line Say::Local(“sayHelloâ€Â?); is the actual code. The word Say is telling Tribes that you are going to say something. The  :: Means that the next word will be tied on to the first which is Say. The word Local is telling tribes that what you say will be in local range. Then Inside the () is the sound name of what you are going to say. Notice this has a ; at the end. This is because it is a code line, and all code lines must have a ; at the end. Ntice that if you type Say:Local(“sayHelloâ€Â?); Inside the Tribes console, it will do the EXACT SAME THING.

If, Else If. Else

They mean exactly what they say. You want to make a function to do something.. But you want it to “think� on it’s own. So if this were to happen, then do this. else if this were to happen, then do this. Or else do this. They are set up almost the same way as functions are, and do not really need a lot of explaining. If you look throught the code you should be able to understand well enough what I’m talking about.

The More Advanced Function

$T::TauntNum = 2;
$T::Taunt[1] = "tauntDance";
$T::Taunt[2] = "tauntMissedMe";

function Taunt(%msg)
    if(%msg == "")
          %msg = floor(getRandom() * $T::TauntNum);

You  may be thinking.. What the hell is that? If you have been paying attention, you should be able to figure out most of it by yourself. The top 2 lines are Global Variables. Remember, they show important information that will be used later. You should be able to figure out what those 3 Global Variables mean.

Then you have your function. The name of this function is Taunt as it’s purpose is to play local taunts when it is called. Notice the %msg between the () brackets. That is a Local Variable that will be used for a certain thing. The next thing is the { bracket which opens the function block. The next thing is an if statement. This is saying If %msg is equal to nothing, then do this. if has brackets of it’s own as it is another form of a function. Now back to where we were. If  %msg is equal to nothing then %msg is equal to (what the hell is that?) floor means a base number. The brackets state what the base number is. In Tribes, there is a function called getRandom somewhere. The fuction’s purpose is to get a random number. next is the * sign. This has to do with the getRandom function. it is used as a multiplication sign and is saying to multiply the next “numberâ€Â? by 1. What it is asking to multiply by one is… (Hey It is the Global Variable!). It is asking to pick a random number of the $T::Taunt variables. It calls $T::TauntNum as it says the amount of numbers that will be used.

What we have here is a random number of these 2 variables. So it is a 50/50 chance that either one of these will be picked.

The next line of code says what we have made in the previous function.. It asks Tribes to Say in a Local area the random message.

Well that is enough of that for now..

Well I need some FAQ to have one, so give me your FAQ so I can answer them and write them in here!
« Last Edit: December 31, 1969 06:00 pm CST by UnderGod »
"The right man in the wrong place can make all the difference in the world"


  • Goblin Pup
  • *
  • Posts: 0
  • Reputation: +0/-0
Re: Tribes Coding Volume 1
« Reply #1 on: November 12, 2002 02:10 am CST »
And to help compliment the guide lemme show you a simple script that i wrote to make rpg things easier. Im using this because its very short and easy to understand.
function Spawnguards(%player, %count)
 for(%i = 0; %i < %count; %i++)
 Ãƒâ€šÃ‚     {
 Ãƒâ€šÃ‚     say(0, "#spawn sloth "@ %player @"-Defender"@ %i @" default 0");  
 say(0, "#follow "@ %player @"-Defender"@ %i @" "@ %player @"");  
 Ãƒâ€šÃ‚     }

Starts with 'function' because thats what it is a function.
Then 'spawnguards' is the name of the function.
%player, and %count are two local variables. Why did i choose local? Because they dont need to be used anywhere else in the game, just for this function.

Now the for() statement is a little tricky to understand if coding isnt your forte. If you dont get it, thats fine, because you probably wont be writing functions just yet with the for() command. But it goes like this :

for(initial value, condition, what to do each loop)
%i = 0
%i is a variable with a random name, i picked a single letter because its faster and easier.
the variable i starts at 0 each time i do this function.
%i < %count
%i is less then %count.
++ is just a shorthand way of saying %i + 1. so if i is equal to 2 then i++ is equal to 3.

Okay now how it works. For is used to make a loop. so you can repeat the function over and over in case you need to.

heres the process broken down into english :
for(%i = 0; %i < %count; %i++)

When i start this loop, %i will be equal to 0.
For each time that %i is less then %count, go ahead and perform the function.
After performing it once, add 1 to %i and do it all over again.

It will keep doing this till i% is not less then %count.

So if %count is 5. Then this loop will repeat 5 times.

say(0, "#spawn sloth "@ %player @"-Defender"@ %i @" default 0");  

"@ %player @"
what this means is to put this variable here. Like if i had a function

function shout(%message) {
say(0, "#shout "@ %message @".");

if %message was "hello there" it woudl shout "hello there"

So when i put this :
say(0, "#spawn sloth "@ %player @"-Defender"@ %i @" default 0");  

it says , as if you typed it : spawnguards("Lucid","5");
#spawn sloth Lucid-Defender 1 default 0
Then remember it repeats however many times %count is?
#spawn sloth Lucid-Defender 2 default 0
#spawn sloth Lucid-Defender 3 default 0
#spawn sloth Lucid-Defender 4 default 0
#spawn sloth Lucid-Defender 5 default 0

So there it would spawn 5 bots.
The code after that just makes the bots follow you. That should give you a practical application of it. I may post another one if it helps later.
« Last Edit: December 31, 1969 06:00 pm CST by Anonymous »