- Quick Links -


Jedi Knight modifying site

Visitor No.72282
Since July 1999

Theme :

Massassi Temple MILLENNIUM
LucasArts Entertainment Company

- Random Picture -

Lightstaff 1.0 MotS

Lightstaff 1.0 MotS

Forum Projects Documents Features Extra Links
Structure of a cog

DOWNLOAD


1

This tutorial will tell how a cog is made, targeting especially for cog beginners, so they can know how a cog is written.


2

First, it's always good to bring up an example cog to learn than just go read tutorials and understand them. So, let me bring a basic cog...kyle.cog! Okay, don't blame me because it's long. I like it that it handles quite a few situations and probably good to understand what a cog can do to the player himself.

Let's just open up the cog and keep it along with this page.


3
# Jedi Knight Cog Script
#
# KYLE.COG
#
# Main script for the player. Handles things like saber info,
# saber blocking animations, invulnerability at respawn, etc.
#
# [YB & CYW]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved

This part is all comments at the top. Any lines starting with "#" is a comment and will be ignored by the engine. It usually tells what the cog is and who made when.


4

Next part is called the symbols section. It starts after "symbols" term is declared. This section is to define variables and messages according to the usage with the cog. Let's look at the first line.

   thing       player                           local

This is telling to the engine that the cog wants to register a "thing" type variable called "player" as "local". There are certain amount of variable types in JK. To name a few, here are some.

int - Integers. (Integers for calculation, can only be used within 1 cog, local to itself.)
flex, float - Flex, Float. (Integers with decimals)
vector - Vectors. (Can contain 3 flexes. For vector calculation)

There are more for engine use and I'll also name them here too.

thing - Things. (player, crates, doors, projectiles, etc)
template - Template. (For thing specifications. Every thing that appears in the level has some kind of spec within itself - Gravity, collision, size, etc.)
sound - Sound. (Stored as "wav" format. Can load and play any sound)
keyframe - KeyFrames. (For 3d animations, stored as "key" files.)
ai - AI. (Artificial intelligence files. Stored as "ai" files in ascii format.)
cog - Cog. (For use with communicating with other cogs.)
sector - Sectors. (Each sector sections in levels.)
surface - Surface. (Surface of a sector.)
material - Mats. (2D images in "mat" format, can be converted from a bmp file.)
message - Messages. (By registering messages, the cog can use those for its operations, more later.)

Let's get back to the first line of the symbols section. The "local" means that the variable will not be interfered from anything else, meaning it will only be used within this cog and will not be changed through anything else. The difference between having "local" or not is simply if you want to use the variable in JED or not. Don't put it if you want to assign a thing to that variable in a level editor. The variable gets global by not putting it.

You can assign anything in the symbols section as a startup operation. For example you can do

int testVar=12 local

in the symbols section to let "testVar" start with 12. Or you can assign a "wav" file as a sound variable too. This applies to any variable types but a few exceptions and I'm not going through it as that is not a big matter right here.

So, that's how most of the symbols section in this cog is made. On the last part, there are variables type of "message". These are very special and cannot be named anything else but what's written there. I'll go each of them but not all of them that exists in JK engine, for all names just check Sender & Source later.

Each messages gets called upon certain events and will go through until the parser finds "return" in the section.

startup - This will get called at every beginning of a level, to be precise a few seconds before the screen loads into the level.
killed - Depends on what the cog is assigned to, but this is "kyle.cog". This message gets called when the player gets killed by some reason.
newplayer - This gets called when the player respawns in multiplayer game. Not for use with singleplayer games.
timer - This will not get called by level events, rather when a cog "SetTimer" is used, this gets called after the timer elapses.
blocked - This is special to the player. Gets called when the player blocks anything with his saber.
skill - This will also not get called by any level event, but by getting "SkillTarget" cog onto the player from another cog, this will respond for it.
damaged - Simple enough. Gets called when the player gets injured.
splash - Gets called when the player enters or exits out of water. splash!
user0 and user1 - As self explanatory, this is user defined(but hard coded) message and will not interfere with any level events but for use with communicating with other cogs basically. Usually a message from another cog gets sent toward userX message by "SendMessage" cog.

That's all in this cog. So you can place any message that you want to trap of its event.

To explain simple here, the cog wants to leave a backpack when the player is killed, wants to know if he needs to make bubble out of his mouth when damaged underwater. Or if he wants to stop his saber swing motion when he suddenly blocks. Thus this cog registers those event messages.

As a small example, if you want to auto save the game as a level finishes, you do this. (You need to register the cog though)

   #my-cool.cog
   #Saves game on level ends
   #By CoolMyself on 2010 July 41st
   symbols
   message shutdown
   end
   code
   shutdown:
      AutoSaveGame();
      Return;
   end

The symbols section can be ended by placing "end" after all the symbols.


5

Now onto the code section. This section is splitted into each messages registered in the symbols section as you may be able to find.

startup:

timer:

etc in the cog and in the end of the message there is always the "Return" cog to tell that the message event is finished there. It does all sorts of thing when these message gets called by whatever event and cogs.


6

Conclusion :

Cog has symbols section to declare variable usages and messages, so the cog knows what events to catch and what kind of variables to use. In the code section, each message has entries until the "Return" cog to make operations for each of the events handled in the cog. Simple as that.


Forum Projects Documents Features Extra Links

Top - Home - Back

PHP Apache Valid XHTML 1.0! Valid CSS!

This site is developed using PHP under Apache server
with XHTML, JavaScript, CSS and Cookie technology.

Certain parts of this site require Cookie support.

This site is best viewed with Internet Explorer 5.5, Netscape 6.0, Opera 6.0 or Mozilla 1.0 and above
at resolution 800 * 600 and higher.

Nothing on this site is made, distributed, or supported by LEC.
Please use and download all materials at your own risk.

© 1999-2004 Hideki.

This page was last modified on Sat, 30 Jul 2011 17:28:41 +0000.