-----------------------
=======================
QuakeC Tutorial Part II
=======================
-----------------------
Hello and welcome to the second part of this tutorial. In this tutorial I will attempt to describe to you the following things:

  * Conditional statements
  * Loops
  * What the built in procedures are and what they do

In my code clips (examples) anything with a couple of /'s infront of it is a comment (Note: This is also what Quake uses for comments. Another method of commenting things in Quake is to put /* at the begining of the comment and */ at the end.)
	Also, throughout the tutorial I use NB to tell you intersting tit-bits of information. I recommend you read them all.

Conditional Statements
======================
Conditional statements are statements that do something only if a certain test turns out to be true. The conditional statement in QuakeC is the 'if' statement. The very basic syntax of the if statement is:

if (variable1 == variable2) do_this_thing;
	or for multiple statements afterwards:
if (variable1 == variable2) 
{
do_this_thing;
and_do_this_thing;
}

As you might have realized in the if statement the stuff inside the brackets is the test. You can test variables in a number of different ways. They are:
(NB. the stuff brackets tell you what must happen for the test to be true)
==	equal to (variable1 has the same value as variable2)
!=	not equal to (variable1 doesn't have the same value as variable2) 
<	less than (variable1 has a value less than variable2)
>	greater than (variable1 has a value greater than variable2)
<=	less than or equal to (variable1 has a value less than variable2 or variable1 is equal to variable2)
>=	greater than (variable1 has a value greater than variable2 or variable1 is equal to variable2)
&	flag test (that bit refered to by variable2 in variable1 must be on - or set to 1) NB. You don't need to know about this one yet.

The test can be joined together using the following:
&&	and or as well as (both tests must be true for this to be true)
||	or (only one of the tests needs to be true for this to be true)

I recommend that each seperate test has its own brackets. eg.:

if ((var1 == var2) && (var2 != var3)) do_something;

It is possible to seperate it out like this for easier reading:

if ((var1 == var2) && (var2 != var3))
	do_something;

There is another feature of the if statement - the else clause. The else clause causes the statement following it (or the satements in brackets following it) to be executed when the if statement is not true. (NB. executing code is not murdering it. It is technical term for running it)
eg.:

if (variable1 == variable2)
	do_something;
else
	do_something_else;

You can a combination of { and } brackets with the if and else statements. eg:

if (variable1 == variable2)
	do_something;
else
	{
	do_something_else;
	and_do_something_else;
	}

Loops
=====
Loops are a way of repeating things. The loop in Quake C is the while loop. It can also take tests just like the if statements. The basic syntax is:

while (var1 == var2)
	do_this_statement;

Again, if you want multiple statements then enclose them in {} brackets.
Since all the test stuff has been explained above that about does it for loops. Here is an example of a loop:

while (var1 < 20)
	var1 = var1 + 1;

In this loop it will continue repeating 'var1 = var1 + 1' until var1 becomes greater than or equal to 20 (var < 20 becomes false or untrue)

The Built In Procedures
=======================
Here is a list of the built in procedures. An explanation of each procedure follows after each one or group.

makevectors 	- Turns the direction facing in a vector
setorigin	- Sets the origin (position) of an entity
setmodel	- Sets the model (what it looks like) of an entity
setsize		- Sets the size of an entity
break		- Stops execution of code
random		- Generates a random number between zero and one
sound		- Plays a sound
ambientsound	- Plays an ambient sound
normalize	- Normalizes a vector (a 3D thing)
error		- Generates an error and stops execution of code
objerror	- Just Generates an error
vlen		- Returns the 'length' of a vector
vectoyaw	- No idea
spawn		- Spawns (creates) an entity in the world
remove		- Removes an entity from the world
traceline	- Finds out what is encountered going along a vector
checkclient	- Returns a client entity
find		- Finds a certain entity by a certain value it has
precache_sound	\  Loads a sound, model or file into the cache to be
precache_model  |- used. Must be done before it can be used
precache_file   /
precache_sound2 \
precache_model2 |- Same as above but loads from pak1.pak not pak0.pak
precache_file2  /
stuffcmd	- Forces a client to execute a console command
findradius	- Checks if an etnity is within a certain radius of
		  another
bprint		- Unreliable message(string) to everybody
sprint		- Sends a reliable message to a specific client
dprint		- Reliable message to everybody
eprint		- Not used
centerprint	- Same as sprint but message in the center not in
		  console
ftos		- Float to string (converts a float to a string)
vtos		- Vector to string (converts a vector to a string)
coredump	- Not used
traceon		- Turns on debugging traces
traceoff	- Turns off debugging traces
walkmove	- No idea
droptofloor	- Checks is an entity will drop to the floor or fall
		  off the level
lightstyle	- Sets a lightstyle to a light (eg. flashing)
rint		- Rounds a float to the nearest integer
floor		- Returns largest integer <= v
ceil		- Returns smallest integer >= v
checkbottom	- Returns true if 'self' entity is on the ground
pointcontents	- Returns the content type (eg. water) at a position
fabs		- Returns the absolute value of a float
aim		- Returns the shooting vector
cvar		- Returns the value of a console variable
localcmd	- Places a local command in the queue
nextent		- Returns the next entity after an entity
particle	- Starts a partical effect (eg. rocket blast)
ChangeYaw	- Changes the yaw of an entity to be idealyaw
vectoangles	- Calculates the angles of a vector
WriteByte	\
WriteChar	|
WriteShort	|
WriteLong	|- Direct client message generation (to a specified
WriteCoord	|  client)
WriteAngle	|
WriteString	|
WriteEntity	/
bWriteByte	\
bWriteChar	|
bWriteShort	|
bWriteLong	|- Drect client message generation (to all clients)
bWriteCoord	|
bWriteAngle	|
bWriteString	|
bWriteEntity	/
movetogoal	- Moves an entity towards its goal (for monsters)
makestatic	- Stops all movement of an entity
changelevel	- Changes the level that is running
cvar_set	- Sets a console variable
setspawnparms	- Sets initial parameters for when an entity is spawned

Thats all of the built in procedures listed. There are many more actually in the original QC code that do helpfull things but they are to numerous to list.
	If you want the argument list of the procedures (the parameters) then they are defined just before the end of def.qc. I advise you not to change them.

The End
=======
Well thats the end of another tutorial. That covers most of the basic stuff. In the following tutorials I will have a lot of commented code that shows some of the more advanced stuff.

Credits
=======
This tutorial was written by James Bielby (aka [Griffin] Marine)
The latest tutorial should be available from
http://ourworld.compuserve.com/homepages/bielby
or from
http://www2.wildnet.co.uk/~shane/marine.htm