Symbols General


The symbols section is used to list variables and give them an initial value. It is not necessary to declare variables in the symbols, but because LEC did, it's considered proper Cog programming. Each cog has a limit on the number of variables of each symbol type that it can store.

There are basically three types of variables: integer, flex, and vector. Sectors, things, surfaces, models, etc all boil down to an integer number.

The symbols section of cogs listed in the items.dat and the static.jkl is loaded only once when JK starts. It is not reloaded with every level. Cogs loaded by the level's JKL will be loaded every time the level is loaded. Also, the values of each cog's variables are stored until you exit JK entirely. When a variable is listed in the symbols section, it is given a value of zero by default.

A variable's type will be reset to match whatever type you assign it to. For example, if you define an integer in the symbols section and then assign that integer to a vector value of '1 2 3', the integer will be turned into a vector to accommodate this new value.

You cannot define a variable in one cog and retrieve its value in another. Even though cog has a variable extension called "local," ommitting this extension will not allow you to access variables in other cogs.

Defining Variables from the Level

If the cog is listed in the World Cog section of a .jkl, the JKL can pass values to the variables in the symbols section. This is how JED gives values to variables in placed cogs. Here's an excerpt from the World Cog section of a JKL:


0:00_door.cog4-1-1-1820.5
1:00_std_elev.cog83985460.2524 
2:01_funicularA.cog12153915508424
3:01_funicularB.cog1617488424 
4:01_cargoelev2.cog19192122   
5:00_door.cog23-1-1-1820.5

The code below is from the first cog listed above, 00_door.cog:

symbols

message startup		
message activate	
message arrived		
message timer		
message blocked		

thing   door0     linkid=0 mask=0x405
thing   door1     linkid=1 mask=0x405
thing   door2     linkid=2 mask=0x405
thing   door3     linkid=3 mask=0x405

float    moveSpeed=8.0
float    sleepTime=2.0
float    lightValue=0.5

sector doorSector       local
int       numDoors=0    local
int       doorStatus       local
int       moveStatus      local
int       i                      local

end
Notice that the seven values listed in the JKL correspond to the seven variables in the symbols section without the "local" extension. The messages listed in the symbols are variables, but they are ignored when JK passes variable values from a JKL.

It is convenient to define level-specific things like the doors in the level so that simple cogs like 00_door become generic. This variable-passing does not work with the static.jkl.

When an object's value is passed from a JKL, the cog will receive messages sent by that object. This is the only way to receive messages sent by sectors and surfaces.