
|
The COG Scripting Language is an event-driven imperative scripting language designed to help level designers write simple interactivity without requiring extensive programming experience. While COG was initially developed as an incremental improvement over the INF Scripting Language used in Dark Forces, COG quickly grew into a more complete language as the level designers continued to request more advanced features.
In addition to the COG implementation provided in Jedi Knight and Mysteries of the Sith, an independently-developed COG Virtual Machine has been written and released under the GNU General Public License as a part of the Sith 2 Project.
At a fundamental level, COG scripts consist of two separate and distinct sections: the first, the symbols section, describes variables that can be manipulated during the execution of the script; the second, the code section, which contains executable information in the form of a C-like compound statement. An example outline follows:
# Comments symbols [Symbol List] end code [Compound Statement] end
The symbols section is nothing more than a list of variables described by their type followed by their name, optionally including a default value and a list of extensions. It begins with the keyword symbols and ends with end.
# Example outlines [type] [name] [type] [name] [extension] [extension] [type] [name]=[value]
Valid symbol types include numeric and logical types:
Resource file types:
Engine constructs:
And internal symbols that cannot carry a conventional value:
Extensions are used to apply specific properties to symbols. There are five extensions recognized by COG:
An example symbols section follows:
# Start symbols section symbols # Messages must be specified in the symbols section # or they cannot be recieved by the COG message startup # Define an integer and assign it a value int i=3 # Define a local thing thing player local desc=local_player_thing # End symbols section end
Similar to the symbols section, the code section begins with the keyword code and ends with end. The code section contains a single C-style compound statement with messages indicated by C-style label statements.
# "Hello, World" Example COG
symbols
message startup
end
code
startup:
print("Hello, World!");
return;
end
# "Hello, World" Over and Over Again
symbols
message startup
message pulse
int max_print=20
int printed=0 local
end
code
pulse:
if(printed == max_print)
{
SetPulse(0);
return;
}
else
{
printed = printed + 1;
print("Hello, World");
return;
}
startup:
SetPulse(5);
return;
end
The COG Language is not without fault. Over the years several incorrect design decisions have become rather grating. For instance, the symbols section is context-sensitive and requires complex two-stage parsing when a slightly different grammar could be parsed much more easily and efficiently in a single stage by a pregenerated component.
In 2005 an independently-developed COG Virtual Machine was released as part of the Sith 2 Project. Although it faithfully emulates the original COG scripts provided with Jedi Knight and Mysteries of the Sith it also offers several of its own advancements.