Notes on System Verbs


Bitwise Verbs

The Bitwise verbs are useful when you want to use hex numbers as flags. You can use the Bitwise Operator '&' instead of BitTest().

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. Unfortunatly, the heap verbs cannot be used to create global variables - each cog works with its own heap, and no other cog can access it.

Let's say that 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:

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

In advanced programming languages, special "pointer" variables are used to store memory addresses. These variables point to a location in memory. But in Cog, it is not so complicated. Pointers are regular integers which hold the value of a slot number. However, these integers will still be called pointers in this reference.

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):

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().