COG Symbol Types

Types

AI

The AI symbol type gets a reference to an AI file. AI files have .ai, .ai0, and .ai2 extensions. Syntax:

  ai     classFile=boc.ai2

Cog

The cog symbol type stores a reference to a cog file. You cannot directly assign a cog to the variable, but a cog value can be passed from a JKL to the symbol. Syntax:

  cog     classCog

Flex

Flexes store numbers with a fractional portion. Syntax:

  flex      var1=1.5

Float

Same as Flex.

Int

Ints (short for integers) store numbers without a fractional portion. Syntax:

  int     var1=5

Keyframe

This symbol type gets a reference to a .key file. Syntax:

  keyframe     keyName=file.key

Material

The material symbol type stores a reference to a .mat file. Syntax:

  material     mat1=dflt.mat

Message

Messages are listed in the symbols section so that the engine will know to look for their handlers in the code section. Messages do not use symbol extensions. Syntax:

  message     startup

Model

The model symbol type gets a reference to a .3do file. Syntax:

  model       yourModel=model.3do

Sector

The sector symbol type stores a reference to a sector. If the sector is passed from a JKL, the cog will receive messages from the sector. Syntax:

  sector      sec1

Mask Info: Sectors can send two messages to a cog, entered and exited. These are sent when a thing passes through the walls of a sector. Masking the sector (adding Mask Flags to the symbol) will stop these messages from being sent if the thing is excluded by the flags. The default mask is thought to be 0x400.

Sound

The sound symbol type gets a reference to a .wav file. Syntax:

  sound     soundName=sound.wav

String

There is no string symbol type, but you can assign string values to variables in the code section. For example:

  string="string here";
  Print(string);

JK's use of strings is not fully known, but you can use string variables in any place that you can enter a string with quotes.

Surface

The surface symbol type stores a reference to a surface. If the surface is passed from a JKL, any messages sent by the surface will be received by the cog. Syntax:

  surface     surf1

Mask Info: Surfaces can send several messages to their cogs. Giving the surface Mask Flags allows the cog to ignore messages from the surface caused by things that were excluded by the mask. Surfaces use a default mask which may be 0x400.

Template

Template symbols store a reference to a template in a JKL. JK does not allow you to use the first template in the static or level JKL as anything other than a base for other templates. Syntax:

  template     temp1=yourTemp

Thing

The thing symbol type stores a reference to a thing. Syntax:

  thing     thing1

Mask Info: Masking things (by adding Mask Flags to the symbol) controls what event messages sent by the thing will be handled by the cog. If the thing which caused the event was excluded by the mask, then the event message will be ignored.

When a projectile hits an actor, the touched message is not normally handled in the actor's cog because the default mask does not allow projectiles. If you give the thing a mask of 0xfff, an event caused by any type of thing will be handled in the cog. The default thing mask may be 0x404.

Vector

The vector type is designed to hold three numbers in one variable. Variables of this type are used for positions, vectors, RGB tints, and anything that needs three numbers. Syntax:

  vector     vec1

You cannot directly assign a value to a vector in the symbols section, but vector values can be passed to the variable from a JKL in this form: (x/y/z). Also, you cannot directly compare one vector to another. This example:

  if(vector1 == vector2) // then whatever 

will not work. You will have to compare each axis of the vectors seperately. With MotS, you can use VectorEqual().

Notes

Symbol Examples

The examples of symbol type syntax given on this page do not have symbol extensions. But all symbol types with the exception of messages can use at least the "local" and "desc" symbol extension. Symbol types for objects that send messages can use all of the symbol extensions.

Most of the examples show the symbol being given an initial value. No variable has to be given an initial value, it is only done in the examples to show that a variable accepts one.

Integer Values

Cog's integers are signed 4-byte values. The maximum value is 2,147,483,647 and the minimum value is -2,147,483,648.

When giving integer values (e.g., operands, arguments): If you exceed the maximum integer, then the integer will "wrap around" to its lowest value and will add from there. If you exceed the minimum integer, then the integer will be given its maximum value and will subtract from there.

When using integers in an operation (e.g, 2147483647 + 10): If the resulting integer exceeds the maximum or minimum integers, Cog will change the result to 2147483648. This number is unsigned and is 1 greater than the maxint.

Floating-point Values

Cog's floating-point types (flexes and floats) are also signed 4-byte values. With no decimal point, these numbers have the same minimum and maximum values as integers (and the same rules apply). But the more decimal digits a float has, the less precise the float will be. This description of "floating-point values" applies to floating-point operations (e.g., modulo) as well.

Precision is a quality of floating-point numbers that describes how many significant digits a variable type can hold. Precision is not constant. The more decimal digits you have, the less precise the number will be.

Cog's floats have a maximum precision of about 9 digits - which means that at the most, a float can store and use 9 significant digits with no loss of precision. The minimum precision is 6 digits (with all significant digits being to the right of the point), but Cog will only display the first 6 decimal digits.

This precision factor is caused by the way fractional numbers are stored in memory. Unlike whole numbers, they are stored approximately. After so many digits of precision, the accuracy of the stored number will fail. Since floating-point numbers cannot always be trusted, you have to be careful with what operations you use them in.

Floating-point Operations

Floating-point numbers spanning more than six digits may suffer a loss of precision. Here are two examples:

  PrintFlex(111.222333 * 1000); 
  "111222.335958" prints. 
  PrintFlex(111222333 % 1000); 
  "336.000000" prints. 

In both examples, the limit of precision in floating-point numbers is visible.

  • Create:
This page was last modified 17:32, 19 December 2005.   This page has been accessed 395 times.