[GSC] Scripting Tutorial #0 - Intro



> >

Created 2 years ago

[GSC] Scripting Tutorial #0 - Intro

A simple introduction into scripting in call of duty 1.1

Intro


CoDScript (also called QuakeC) is basically a scaled-down version of C. If you know C/C++/Java/PHP you'll be able to learn this language. It's very simple. There are some major differences between these languages and CoDScript though!

Info: This tutorial has originally been published by cheese on wy6.org, which has closed in january 2015. He kindly gave us permission to keep this tutorial alive on think-clan.com.



Variables



For variables, you don't have to initialize them. Ever. Take this code for example:

C:
int variable = 1;
printf( "%d", variable );
GSC:
variable = 1;
iPrintLn( variable );


Because you don't have to initialize the variable and define what type it's going to be, you can have variables that can change types all the time.

C:
// would cause compiler errors
int variable = 1;
variable = "a string";
variable = 1.46899;
GSC:
// works just fine
variable = 1;
variable = "a string";
variable = 1.46899;


Never having to initialize variables is nice in a way, but also can be bad if you have a variable that is SUPPOSED to be an int, but really is a string.


Variable Types


There are MANY types of variables in CoDScript. All the standard C ones apply, with the addition of CoD-specific variables.

C:
int				1
float			3.14159
double			1.22
char				'c'
GSC:
bool			true/false
string			"text"
localized string	&"text"
entity			players, models
struct			structures of data like in C, except as types
vector			(1, 2, 3) x,y,z



Functions



Unlike C, you don't have to create functions with return types.

C:
int main();
void coolFunction();
float getMahFloat();
GSC:
main();
coolFunction();
getMahFloat();


As with variables, you don't have to specify types in the parameters either.

C:
char* getName( entity_t ent )
{
	// code
}
GSC:
getName( ent )
{
	// code
}



Other notes



CoDScript does NOT support any pre-processor directives (those that start with #)! So, you cannot include any files or really make any 'C'-style global defines. Instead, you would do things like this:

C:
// including function/calling it
#include <stdio.h>

printf( "Cool stuff!" );
GSC:
// calling a function in another file - file is _coolfile.gsc in the maps\ folder
maps\_coolfile::printf( "this" );
[[ variable ]]( "this" );


To set global variables, you can use the 'level' variable.

C:
// old C-Style
#define VAR 1
GSC:
level.var = 1;


In the same way, you can actually make 'level' variables contain links to functions in other files!
level.coolFunction = maps\_utility::loadThisAndThat;

// somewhere else in another file
[[ level.coolFunction ]]();


Closing



So now you know a bit more about how to script for CoD! Check out the script reference to see all the built-in functions available (this is a CoD4 reference, although most of the functions work in CoD1). Stay tuned for some more tutorials on CoDScripting.

Tutorial Details

Created: 2 years ago by ^w Y 6 | Cheese

Views: 2599 Views

Keywords: Scripting, quakec, gsc, modding, coding,

Share this Knowledge with your friends!

Direct Link:

2 Comments

good information :)
Commented by _outlaw:lazzy  (Feb 18th, 2015 03:56 PM)

nice intro :v
Commented by `~Fres{h}lo!c~  (Feb 23rd, 2015 12:10 PM)

Please sign in or create an account to post a comment.