How To Cog - Chapter 1.2 - Cog Basics

Cog Files

Cog files are just regular text files with a .cog extension. Jedi Knight will look for cog files in a resource subfolder named cog. This folder can be in several different places - which we'll get to later on.

A cog is just lines of text that don't do anything. When JK loads a level and all the cogs needed for it, these cogs are stored in memory. When JK needs to use one of them, it reads the information it loaded from the cog file and performs whatever instructions the cog contained. The point is that the cog does nothing - it is simply a text file that JK interprets when it needs to.

Each time JK finds an entry for a cog file (such as in a JKL file - covered later), it will load that cog. It doesn't matter if there's more than one entry for a cog - multiple copies of a cog can be loaded with no connection to each other.


Cogscripts are event based. An event happens in the game, and JK looks for code to run for that event. There may or may not be code for that event, and for some events JK doesn't bother using cogs. But every cog works by associating itself with either some part of a level or an object in it. When something happens to one of the cog's associated objects, JK will process the event and look for corresponding code in that cog.

Cogs are often called cogscripts (or just scripts) because in programming jargon, a script is interpreted code with subroutines that are called in response to events. For example, a player dies in the game and JK needs to run the code that handles a player death. JK will process a "killed" event and send a message to the player's associated cogs that have code to run for killed event. Kyle.cog (which is assigned to the player) will receive that message and run the code that it has for the killed message. In a multiplayer game, you'll see a backpack appear as this code is run.

The player's death can be called a "scripted event" because there was a cog waiting to receive a message and run code for that event. The cog doesn't really receive messages and run code - the JK engine is doing all the work here. It's just easier to think of a cog as it's own little program.

Cog Types

There are three different types of cogs: level, class, and inventory cogs. They're all scripts and have the same syntax, but JK uses them for different purposes. Level cogs are loaded by a jedi knight level file (a .jkl). This file contains all of the level's geometry and lists for every type of resource that JK needs to load the level. Level cogs are usually loaded to control specific objects in the game like elevators and doors.

Class cogs are also listed in the jkl file, but in a different section. Whereas level cogs are loaded to control specific things that will be in the level, class cogs are assigned to types of things like players, stormtroopers, and grenades. Class cogs may control many objects in the game at once.

Inventory cogs (AKA item cogs) are loaded by the items.dat file. The items.dat is the initial list of what items your player has while he's in a level. Inventory cogs control these items. Your weapons, items, force powers, and shields are all listed in the items.dat and controlled by inventory cogs.

Previous: Introduction Up: How To Cog Next: JK Levels
  • Create:
This page was last modified 13:56, 14 April 2006.   This page has been accessed 1,503 times.