This document shows usage instructions for every template that Graphgame provides.
Initialize the game. This must be the first template called.
initialize!();
Registers an action and runs it on update.
registerAction!(actionName: string);
Creates a new object.
definition - is a body containing the object's definition, comprised of the below templates.
createObject!(definition: Body);
Add a behavior to an object.
useBehavior!(behaviorName: string);
Set the value of an object's variable (during compilation). This must be used before a variable is marked as mutable.
setObjectVal!(variableName: string, val: number);
Creates a new behavior.
definition - is a body containing the behavior's definition, comprised of the below templates.
createBehavior!(name: string, definition: Body);
Extends a behavior. The supplied definition will be added to the behavior's current definition.
definition - is a body containing the behavior's definition, comprised of the below templates.
extendBehavior!(name: string, definition: Body);
Marks a behavior's variable as mutable (changable after compilation).
setMut!(variableName: string);
Marks a behavior's variable as mutable (changable after compilation), but inlines it instead of exporting it.
setInline!(variableName: string);
Get the value of a behavior's variable. A boolean can be supplied to get the currently saved value instead of the current value.
saved - is whether to use the currently stored (saved) variable or the one that has been updated but not yet saved.
getVal!(variableName: string, saved?: boolean);
Set the value of a behavior's variable (during compilation). This must be used before a variable is marked as mutable.
setVal!(variableName: string, val: number);
Set the value of a behavior's variable (during compilation) using a zero-based argument that was passed to the behavior when it was added to the GameObject. This must be used before a variable is marked as mutable.
setValArgs!(variableName: string, arg: number, defaultVal?: number);
Set the value of a behavior's variable on update (during runtime). Running this will automatically mark a variable as mutable.
body - is the body of the function that will be run to update the variable. This function has access to the name of the variable that is updating without using getVal.
setValAction!(variableName: string, body: Body, priority?: number = 0, exported?: boolean = false, variable?: boolean = false);
Create an action that sets the value of a behavior's variable (during runtime). This must be run manually (or as the click property of an object). Running this will automatically mark a variable as mutable.
body - is the body of the function that will be run to update the variable. This function has access to the name of the variable that is updating without using getVal.
noRegisterSetValAction!(variableName: string, body: Body, actionName?: string, priority?: number = 0);
Create custom declarations on the behavior. This is ideal for graphs, polygons, points, etc, but should not be used for named declarations (functions, consts, etc).
body - is a body that contains outer declarations (polygon, graph, etc). These outer declarations can use getVal, and will be created for every object that the behavior exists on.
behaviorCustom!(body: Body, priority?: number = 0);
Allows modifying the display properties of any object that this is attached to.
body - is a body that contains the display properties that will be applied to each renderer that is attached to the object that this behavior is attached to.
setDisplay!(body: Body, priority?: number = 0);
Gets a zero-based argument that was passed to the behavior when it was added to the GameObject.
getBehaviorArgs!(arg: number);
Allows creating helper methods at certain priorities, and which are only output if the behavior they are attached to is used.
body - is a body that contains helper methods or constants (or any other outer declaration). These will only be exported once and will only be exported if the behavior is used.
helper!(body: Body, priority?: number = 0);
Gets the ID of the object that this behavior is currently attached to.
objectID!();
Creates a new prefab.
definition - is a body containing the prefab's definition, comprised of the below templates.
createPrefab!(name: string, definition: Body);
Extends a prefab. The supplied definition will be added to the prefab's current definition.
definition - is a body containing the prefab's definition, comprised of the below templates.
extendPrefab!(name: string, definition: Body);
Add a behavior to a prefab. Any additional arguments will be passed to the behavior. To use prefab arguments, wrap the number in quotes, which will now indicate the index of the prefab argument.
useBehavior!(behaviorName: string);
Set the value of an object's variable (during compilation). This must be used before a variable is marked as mutable. To use prefab arguments, wrap the number in quotes, which will now indicate the index of the prefab argument.
setPrefabVal!(variableName: string, val: number | string);
Creates a new object from a prefab. Any additional arguments will be passed to the prefab.
definition - is a body containing the new object's definition, comprised of the object templates.
usePrefab!(prefab: string, body?: Body);
Sets a specific ID to be the one used by select templates.
selectID!(id?: number);
Gets the currently selected ID.
selectedID!();
Selects every object and uses the specified body on each.
body - is a body of inner or outer declarations that will be used for each object that is selected.
array - is whether the output should be done as an array.
selectAll!(body: Body, array?: boolean);
Selects every object that has a specific behavior and uses the specified body on each.
body - is a body of inner or outer declarations that will be used for each object that is selected.
array - is whether the output should be done as an array.
selectBehavior!(behavior: string, body: Body, array?: boolean);
Marks the current object's variable as mutable (changable after compilation).
setMutSelect!(variableName: string);
Marks the current object's variable as mutable, but inlines it instead of exporting it.
setInlineSelect!(variableName: string);
Get the value of the current object's variable. A boolean can be supplied to get the currently saved value instead of the current value.
saved - is whether to use the currently stored (saved) variable or the one that has been updated but not yet saved.
getValSelect!(variableName: string, saved?: boolean);
Set the value of the current object's variable (during compilation). This must be used before a variable is marked as mutable.
setValSelect!(variableName: string, val: number);
Set the value of the current object's variable on update (during runtime). Running this will automatically mark a variable as mutable.
body - is the body of the function that will be run to update the variable. This function has access to the name of the variable that is updating without using getVal.
setValActionSelect!(variableName: string, body: Body);
Create an action that sets the value of the current object's variable (during runtime). This must be run manually (or as the click property of an object). Running this will automatically mark a variable as mutable.
body - is the body of the function that will be run to update the variable. This function has access to the name of the variable that is updating without using getVal.
noRegisterSetValActionSelect!(variableName: string, body: Body, actionName?: string);
Gets the display properties for the current objects, and inserts them in place of this template.
getDisplay!();