General Syntax

A template is a script with a C-like syntax which can read and process data from the open file and annotate it by setting data types, adding comments, etc. Unlike a C program, templates do not have an entry point (i.e. a main function) - they are executed from top to bottom like a shell script.

The most simple template is one that just defines some variables, which will set comments and data types in the file, for example:

int magic;
int values[4];

Would produce a file like the following:


The variables you define can also be read in the template, for example to determine the length of an array from data in the file:

int magic;
short size;
int values[size];

That example is like the first, except the number of elements in the "values" array comes from another variable read from the file rather than being hardcoded.

Local variables

Local variables are variables that are scoped to the block they are defined in. Unlike normal variables, declaring a local variable will not annotate the file or advance the file position.

Local variables are used for temporary storage within scripts - for example loop counters, values read from the file using the File Read APIs, etc.

local int x = 0;

Private variables

Private variables are like normal variables, except they will not be annotated in the editor or exported from structs. This can be used for reading structured data from the file and then processing it yourself.

The below example shows a function which can be used to read a data structure from an arbitrary point in the file.

struct vec3f
{
	double x;
	double y;
	double z;
};

struct vec3f read_vec3f(int64_t offset)
{
	int64_t saved_offset = FTell();
	
	FSeek(offset);
	private struct vec3f v;
	
	FSeek(saved_offset);
	return v;
}