COG Verbs - System

Notes:

Bit Verbs

The Bit Verbs are useful for making your code more readable, but for not much more than that. Operators can be used instead.


Master Cogs

A cog can be designated as the master cog so that other cogs in the game can use GetMasterCog() to reference it. These other cogs would use a command like SendMessage(GetMasterCog(), user0); to send a message to the master. Endlevel and startup cogs are usually made the master so they can easily receive messages from other cogs in the level.


Load Resource Verbs

The LoadRes verbs allow you to get a reference to sounds, models, keyframes, and templates without using the symbols section. There is no known difference between a resource loaded with the symbols and a resource loaded by the LoadRes verbs. They will both work the same. But with these verbs, you do not have to define an intermediate variable. So instead of:

 temp=LoadTemplate("shieldrecharge");
 CreateThing(temp, player);

You can use:

 CreateThing(LoadTemplate("shieldrecharge"), player);


Heap Verbs

The heap verbs are used to dynamically create storage for variable values. You don't often need to do this in cog, but it is useful when you don't know exactly how many values that you'll have to store. The heap verbs cannot be used to create global variables. Each cog works with its own heap, and no other cog can access it.

Suppose you want to create five storage slots in memory. You would use HeapNew(5) to create the five new slots. Imagine that it looks like this:

image:heap.GIF

The last memory slot in the heap is slot 4. The five memory slots that we created range from 0 to 4.

In languages like C++, special "pointer" variables are used to store memory addresses. These variables point to a location in memory. Cog is not so complicated. Its pointers are regular integers which hold the value of a slot number.

None of the slots have a value until you use HeapSet(pointer, value) to assign a value to one of the slots. If you try to use HeapGet() to return the value of a slot before it has been assigned a value, JK will crash (or if there is no heap, it will return zero). This next diagram shows the result of HeapSet(0, 999):

image:heapval.gif

Now, the value 999 is stored in the first memory slot. To retrieve it, use HeapGet(0). Suppose that you need to erase the heap's memory slots. You would use HeapFree(). This verb will remove all of the storage space that JK has allotted for the cog. A cog's heap is not affected by Reset().

  • Create:
This page was last modified 00:12, 3 April 2006.   This page has been accessed 449 times.