temp=LoadTemplate("shieldrecharge"); CreateThing(temp, player);You can use:
CreateThing(LoadTemplate("shieldrecharge"), player);
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().