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(0, 5) to create the five new slots. Imagine that it looks like this:
The last memory slot in the heap cannot be used. A sixth slot (slot 5) is created so that we have five available slots.
In advanced programming languages, special "pointer" variables are used to store memory addresses. The variables point to a specific 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 by 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).
Now 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().