- Quick Links - |
Visitor No.72282 |
- Random Picture - | ||||||
|
Structure of a cog
This tutorial will tell how a cog is made, targeting especially for cog beginners, so they can know how a cog is written.
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.
# 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.
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.) There are more for engine use and I'll also name them here too. thing - Things. (player, crates, doors, projectiles, etc) 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. 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.
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.
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. |
This site is developed using PHP under Apache server 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 |