Init Block
Init Block

Init Block

Init ( )

The initialization block of every element in the module. Called on each element when the module is first initialized.

Valid on Elements

Parameters

No Parameters

When it is Called

The init() block is called on each element when TAME needs to create a new context.

The best thing to do in init() blocks are setting variables on the element it is initializing. You can theoretically do anything in these blocks, but it may be better to set up object ownership and other enviromental things in the start() block on the world, since it gets called after all init() blocks are called.

It is important to note that you cannot guarantee the order in which init() blocks are called on each element.

Elements are not required to have init() blocks. Inheritance rules still apply.

Example

Init/Start Example


object o_thing named "thing"
{
	init()
	{
		textln("Init thing.");
	}	
}

object o_ball named "ball"
{
	init()
	{
		textln("Init ball.");
	}	
}

object archetype o_key
{
	init()
	{
		textln("Init " + identity(this));
	}	
}

object o_key_wood : o_key named "wooden key", "key";
object o_key_silver : o_key named "silver key", "key";

world
{
	init()
	{
		textln("Init world.");
	}
	
	start()
	{
		textln("All init blocks called.");
		quit;
	}
}

See Also

Start() — Called after all init() blocks are called.

Additional Technical Notes

When we say that "you cannot guarantee the order in which init() blocks are called," this means that you cannot rely on any element in TAME to initialize elements in the same order, or on any determined order in any implementation of TAME, on any platform that TAME runs on.

A good guideline is to not write code in init() blocks that rely on the value of a variable on other elements, or relies on object ownership of other elements, or any other element's context-specific state.

Initializing a context is wrapped in one request-response loop. The response cues that come back are the result of all init() blocks plus start(). All operations executed contribute towards the operations and function depth limits, which is TAME's soft protection against infinite loops and stack overflows. This may vary by implementation, but the author can override these in the module header.

After the context initialization, TAME does not execute the afterSuccessfulCommand() block, afterFailedCommand() block, nor the afterEveryCommand() block. Initialization does not count as a "command" executed.

×

Modal Header