Getting Started: Difference between revisions

From COD Modding & Mapping Wiki
Jump to navigation Jump to search
(New page: == Getting Started == This section will include serveral things you need to know before you start scripting. Image:Nutshell.png All scripts are contained within simple text files...)
 
No edit summary
Line 1: Line 1:
== [[Getting Started]] ==
== [[Getting Started]] ==


This section will include serveral things you need to know before you start scripting.
This section will include several things you need to know before you start scripting.


[[Image:Nutshell.png]] All scripts are contained within simple text files that contain no formatting, so programs such as Word are not to be used. The file format used for scripts within the Call of Duty series is 'GSC' (.gsc). It is recommended you use a simple but effective editor for programming, such programs include Crimson Editor, Programmers Notepad and Editplus.
[[Image:Nutshell.png]] All scripts are contained within simple text files that contain no formatting, so programs such as Word are not to be used. The file format used for scripts within the Call of Duty series is 'GSC' (.gsc). It is recommended you use a simple but effective editor for programming, such programs include [http://www.crimsoneditor.com/ Crimson Editor], [http://http://www.pnotepad.org/ Programmers Notepad] and [http://www.editplus.com/ Editplus].


A few things you need to know before reading any further are a few common words used within scripting.
A few things you need to know before reading any further are a few common words used within scripting.


Variables: variables are data storage locations which are assigned a name. For example...
'''Variables:''' variables are data storage locations which are assigned a name. For example...
 
<pre>
  intVar = 1;
  integerthing = 1; //by the way, comments like this can be made using //, and are ignored by the game.
  floatVar = 0.5;
  floatthing = 0.5;  
  strVar = "Text";
  stringthing = "Text and symbols 1234567890";
  boolVar = true;
  booleanthing = true; //another thing, almost every line must have a ; at the end or the script won't work. More on that later.
 
</pre>
The variables are declared on the left, and assigned a piece of data such as an integer (whole number), float (a number containing a decimal), string (text) or a boolean (true/false).
The variables are declared on the left, and assigned a value such as an integer (whole number), a float (a number containing a decimal), a string (text and symbols) or a boolean (true/false).


Entity: this is something that is used in maps which can be called in the script. Entities include players, guns, objectives, script_models, etc.
'''Entities:''' These are objects that are used in maps, and can be referenced in the script. Entities include players, dropped guns, objectives, script_models, etc.


They can be called using their relative targetname or classname which is defined in the map.
They can be referenced using their their targetname or classname that has been set within the map.
 
Functions: an action or procedure that can be called or threaded and can return a value. For example...


'''Functions:''' an action or procedure that can be called or threaded and can return a value. For example...
<pre>
  funcMove()
  funcMove()
  {
  {
   self moveY(320, 3);
   self moveY(320, 3);
  }
  }
</pre>
The main function in the above code is '''funcMove()''', and it will perform the actions inside the curly braces when it runs. There is also another function, '''moveY''', which is a built-in function inside COD4, and moves an entity on the Y axis.


The function in the above code is called "funcMove", when called, it will perform the actions inside the brackets.
'''Arguements:''' These are key piece of information that are passed along to functions, and can be any type of object (entity, string, boolean etc). The function that was passed the arguments can then reference them.
 
Arguement: these are required pieces of data that needs to be sent when requested from functions.


For example, if a function is shown as
For example, if a function is shown as
 
<pre>
  function(arg1, arg2)
  function(arg1, arg2)
 
</pre>
The function is asking for two arguements to be sent to the function. An example of this in use...
The function is asking for two arguements to be sent to the function. An example of this in use...
 
<pre>
someotherstuff()
  {
  {
ent function(320, 5);
  ent function(320, 5);
  thing function(320, 5);
  }
  }


  function(dis, time)
  function(distance, time)
  {
  {
ent moveZ(dis, time);
  ent moveZ(distance, time);
  }
  }
</pre>
As you can see, function() is called on both 'ent' and 'thing', and the two arguments '320' and '5' are passed to the new function as 'distance' and 'time'. Then moveZ is called on the entities.


As you can see, 'dis' is called and is given the value of 320, this can then be used as a variable called 'dis', ditto for time.
'''Calling/Threading:''' these are used with functions. Functions can be threaded or called sequentially.
 
Calling/Threading: these are used with functions. A function can be called or they can be threaded.
 
If a function is threaded, then the function is performed while the script continues, whereas if a function is called, the script will wait until the function is completed before it continues. Examples...
 
function(); // This is how to call a function
thread function(); // This is how to thread a function[/code]
 
 
Self: this is used inside functions when a function is called on an entity. Self is used instead of an entity.


For example... (You will see in this example that in the function, called function(), self is equal to 'ent' which was decalred in a different function)
If a function is threaded, then that function is performed while the script continues, whereas if a function is called sequentially, the script waits until the function is completed before it continues. Examples...
<pre>
function(); //the script will stop at this line and carry out function() before going down to...
thread function(); //this will start function() and carry on to execute 'ent moveZ'
ent moveZ(350, 5);
</pre>
'''Self:''' If you call a function on an entity e.g 'unnamedent thread dostuff()', then within the function dostuff(), you can refer to unnamedent as 'self'.


For example...
<pre>
something()
  {
  {
   ent = getent("ent","targetname");
   ent = getent("ent","targetname");
Line 69: Line 73:
   self moveZ(150, 5);
   self moveZ(150, 5);
  }
  }
</pre>

Revision as of 02:35, 24 October 2008

Getting Started

This section will include several things you need to know before you start scripting.

All scripts are contained within simple text files that contain no formatting, so programs such as Word are not to be used. The file format used for scripts within the Call of Duty series is 'GSC' (.gsc). It is recommended you use a simple but effective editor for programming, such programs include Crimson Editor, Programmers Notepad and Editplus.

A few things you need to know before reading any further are a few common words used within scripting.

Variables: variables are data storage locations which are assigned a name. For example...

 integerthing = 1; //by the way, comments like this can be made using //, and are ignored by the game.
 floatthing = 0.5; 
 stringthing = "Text and symbols 1234567890";
 booleanthing = true; //another thing, almost every line must have a ; at the end or the script won't work. More on that later.

The variables are declared on the left, and assigned a value such as an integer (whole number), a float (a number containing a decimal), a string (text and symbols) or a boolean (true/false).

Entities: These are objects that are used in maps, and can be referenced in the script. Entities include players, dropped guns, objectives, script_models, etc.

They can be referenced using their their targetname or classname that has been set within the map.

Functions: an action or procedure that can be called or threaded and can return a value. For example...

 funcMove()
 {
   self moveY(320, 3);
 }

The main function in the above code is funcMove(), and it will perform the actions inside the curly braces when it runs. There is also another function, moveY, which is a built-in function inside COD4, and moves an entity on the Y axis.

Arguements: These are key piece of information that are passed along to functions, and can be any type of object (entity, string, boolean etc). The function that was passed the arguments can then reference them.

For example, if a function is shown as

 function(arg1, arg2)

The function is asking for two arguements to be sent to the function. An example of this in use...

 someotherstuff()
 {
   ent function(320, 5);
   thing function(320, 5);
 }

 function(distance, time)
 {
   ent moveZ(distance, time);
 }

As you can see, function() is called on both 'ent' and 'thing', and the two arguments '320' and '5' are passed to the new function as 'distance' and 'time'. Then moveZ is called on the entities.

Calling/Threading: these are used with functions. Functions can be threaded or called sequentially.

If a function is threaded, then that function is performed while the script continues, whereas if a function is called sequentially, the script waits until the function is completed before it continues. Examples...

 function(); //the script will stop at this line and carry out function() before going down to...
 thread function(); //this will start function() and carry on to execute 'ent moveZ'
 ent moveZ(350, 5);

Self: If you call a function on an entity e.g 'unnamedent thread dostuff()', then within the function dostuff(), you can refer to unnamedent as 'self'.

For example...

 something()
 {
  ent = getent("ent","targetname");
  ent function();
 }

 function()
 {
  self moveZ(150, 5);
 }