Skip to content

Functions, Constants, and Keywords

Anynam edited this page Jun 21, 2026 · 7 revisions

General Info

  • UTScript uses semicolons (;) to signify the end of a line.
  • Surrounding a variable name in a string ("Hello {name}!") replaces it with the variable value (Hello Chara!).
  • You can alter variables using =, +=, -=, *=, and /=.
  • This page will not include deprecated functions.
  • Layer nodes for rooms are labelled as "Layer" and then the layer number. e.g. "Layer1", "Layer2" and so on.

Constants and Enums

Constant variables.

General Constants

Constants without a specific purpose.

self - Refers to whatever node is currently running the script.

Timer Constants

Time constants.

TIMER - The time in seconds since the script began.
DELTA - The time in seconds since the last frame. Because the game runs at 30fps, this is normally ~0.03.
GLOBALTIMER - The time in frames since the game was opened.

Tween Constants

Constants to be used for tween functions.

EASE_IN,EASE_OUT,EASE_IN_OUT,EASE_OUT_IN - Tween eases.
TRANS_LINEAR,TRANS_SINE,TRANS_QUINT,TRANS_QUAD,TRANS_EXPO,TRANS_ELASTIC,TRANS_CUBIC,TRANS_CIRC,TRANS_BOUNCE,TRANS_BACK,TRANS_SPRING - Tween transitions.

Vector constants

Vector constants for all four cardinal directions.

DIR_LEFT - A vector value of (-1,0).
DIR_DOWN - A vector value of (0,1).
DIR_UP - A vector value of (0,-1).
DIR_RIGHT - A vector value of (1,0).

Angle constants

Positive-only angle constants.

ANGLE_LEFT - A number value of 270.
ANGLE_DOWN - A number value of 180.
ANGLE_UP - A number value of 0.
ANGLE_RIGHT - A number value of 90.

Color constants

Ported directly from Gamemaker Studio.

C_AQUA - A color value of (0,255,255).
C_BLACK - A color value of (0,0,0).
C_BLUE - A color value of (0,0,255).
C_DARKGRAY - A color value of (64,64,64).
C_FUCHSIA - A color value of (255,0,255).
C_GRAY - A color value of (128,128,128).
C_GREEN - A color value of (0,128,0).
C_LIME - A color value of (0,255,0).
C_LIGHTGRAY - A color value of (192,192,192).
C_MAROON - A color value of (128,0,0).
C_NAVY - A color value of (0,0,128).
C_OLIVE - A color value of (128,128,0).
C_ORANGE - A color value of (255,160,64).
C_PURPLE - A color value of (128,0,128).
C_RED - A color value of (255,0,0).
C_SILVER - A color value of (192,192,192).
C_TEAL - A color value of (0,128,128).
C_WHITE - A color value of (255,255,255).
C_YELLOW - A color value of (255,255,0).

Soul mode constants

To be used with setSoulMode.

MODE_RED - Red soul mode.
MODE_BLUE - Blue soul mode.

Variable Types

STRING - A text value.
NUMBER - An int or float value.
BOOL - A true/false value.
UNDEFINED - Only meant to be used internally (non-UTScript). A variable of this type cannot be set and will only have its initial value.
ARRAY - A list value.
COLOR - A color value. Should be set using color().
VECTOR2 - A vector value. Should be set using vec2().
STRUCT - An object value with internal properties. Not implemented yet.
NODE - A reference to a node.
AUDIO - A reference to an audio file.
TEXTURE - A reference to an image file.
SIGNAL - A reference to a node signal, normally used with await.

Keywords

Important non-function keywords.

if/elif/else

Usage: Run code only under specific conditions.
Syntax: if (condition) {code} elif (condition) {code} else {code}
Example:

if (myNum == 0) {
	// myNum is 0
} elif (myNum == 1) {
	// myNum is 1
} else {
	// myNum is something else
};

while/break

Usage: Run code repeatedly while specific conditions are met.
Syntax: while (condition) {code}
Example:

while (myNum != 10) {
	print(myNum);
	myNum += 1;
};
while (true) {
	print(myNum);
	myNum += 1
	if (myNum == 20) {
		break;
	};
};

repeat

Usage: Run code repeatedly a certain amount of times.
Syntax: repeat (amount : number) {code}
Example:

repeat (10) {
	print(randi(1,10));
};

await

Usage: Waits for a function or signal to complete with certain case exceptions.
Syntax: await process : any
Example:

await process_frame; // does the same thing as wait_frames(1)
await get(myAudioPlayer,"finished");

function

Usage: Defines a custom function that can only be used by the node running the script.
Syntax: function myFunction() {code} Example:

function hello() {
	print("Hello {PARAM1}!");
};
hello("Chara"); // prints "Hello Chara!"

globalfunction

Usage: Defines a custom global function that can be ran by any script.
Syntax: globalfunction myFunction() {code} Example:

globalfunction hello() {
	print("Hello {PARAM1}!");
};
hello("Chara"); // prints "Hello Chara!"

General Functions

Functions that can be used no matter what kind of script is running.

initvar

Usage: Initializes a variable.
Syntax: initvar(name : identifier,type : type,initialValue : any = null)
Example: initvar(myNum, NUMBER, 42);

initglobal

Usage: Initializes a global variable that can be used by any script.
Syntax: initglobal(name : identifier,type : type,initialValue : any = null)
Example: initglobal(myNum, NUMBER, 42);

startDialogue

Usage: Starts dialogue.
Syntax: startDialogue(dialogue : Array,bottom : bool = true)
Example: startDialogue(["* Test dialogue 1.","* Test dialogue 2!"]);

set

Usage: Sets the property of a node. Acts the same as set_indexed() in Godot.
Syntax: set(node : Node, property : string, value : any)
Example: set(self, "position", vec2(160,120));

get

Usage: Returns the property of a node. Acts the same as get_indexed() in Godot.
Syntax: get(node : Node, property : string)
Example: print(get(self, "position"));

setvar

Usage: Sets a UTScript variable of another node. For GDScript variables, use get. setvar is only for UTScript variables
Syntax: setvar(node : Node,variable : String,value : any)
Example: setvar(getNode("sprite"), "targetAnimation", "animation2");

tween_property

Usage: Tweens the property of a node.
Syntax: tween_property(node : Node,property : string, value : any, tween_time : number,easing : EASE = EASE_IN_OUT,trans : TRANS = TRANS_LINEAR)
Example: tween_property(self, "position:x", 240, 1.5, EASE_IN_OUT, TRANS_CUBIC);

sin

Usage: Gets the sine of an angle in degrees.
Syntax: sin(angle : number, multiplier : number = 1)
Example: sin(TIMER, 2);

cos

Usage: Gets the cosine of an angle in degrees.
Syntax: cos(angle : number, multiplier : number = 1)
Example: cos(TIMER, 2);

wait

Usage: Pauses the script for a specific amount of time (in seconds).
Syntax: wait(seconds : number)
Example: wait(2);

wait_frames

Usage: Pauses the script for a specific amount of time (in frames). 30 == 1 second, usually.
Syntax: wait_frames(frames : number)
Example: wait_frames(60);

randi

Usage: Returns a random whole number (integer) from a range.
Syntax: randi(min : number, max : number)
Example: randf(1, 10);

randf

Usage: Returns a random decimal number (float) from a range.
Syntax: randf(min : number, max : number)
Example: randf(0, 1);

round

Usage: Rounds a decimal number to the nearest whole number.
Syntax: round(value : number)
Example: round(3.14); // returns 3

is_key_pressed

Usage: Returns true/false depending on whether a key is pressed or not.
Syntax: is_key_pressed(key : string)
Example: is_key_pressed("C");

to_num

Usage: Converts a value to a number. e.g. "24" = 24, true = 1
Syntax: to_num(value : any)
Example: to_num("12");

to_str

Usage: Converts a value to a string. e.g. 24 = "24", true = "true"
Syntax: to_str(value : any)
Example: to_str(12);

to_bool

Usage: Converts a value to a boolean (true/false). e.g. 1 = true, "false" = false
Syntax: to_bool(value : any)
Example: to_bool(1);

lerp

Usage: Returns a value between two points at a position from 0 to 1.
Syntax: lerp(from : number, to : number, at : number)
Example: lerp(get(self,"position:x"), get(target,"position:x"), 0.2);

vec2

Usage: Returns a vector value.
Syntax: vec2(x : number, y : number)
Example: vec2(640, 480);

color

Usage: Returns an RGBA color value.
Syntax: color(r : number, g : number, b : number, a : number = 255)
Example: color(255,0,255);

get_at_index

Usage: Get a value at a specific index of an array, vector (0 is x and 1 is y), or string. 0 is the first value, and it increases.
Syntax: get_at_index(value : array/vector/string, index : number)
Example: function([640, 480, 960, 540], 3);

createSprite

Usage: Creates a Sprite2D node and returns a reference to it.
Syntax: createSprite(name : string, position : vector, sprite : texture)
Example: createSprite("Sprite", vec2(160,120), loadTexture("sprite"));

createAnimatedSprite

Usage: Creates an AnimatedSprite2D node and returns a reference to it.
Example: createAnimatedSprite(name : string, position : vector2, sprite_frames : SpriteFrames = null)
Syntax: createAnimatedSprite("AnimatedSprite", vec2(160,120), getAnimation("testAnimation"));

font

Usage: Gets a font file.
Syntax: font(filename : string)
Example: font("Comic Sans UT.otf");

getAnimation

Usage: Returns SpriteFrames data from a JSON file.
Syntax: getAnimation(filename : string)
Example: getAnimation("testAnimation");

stopAnimation

Usage: Stops an AnimatedSprite2D.
Syntax: stopAnimation(sprite : node)
Example: stopAnimation(getNode("AnimatedSprite"));

playAnimation

Usage: Plays an AnimatedSprite2D, and optionally start a different animation.
Syntax: playAnimation(sprite : node, animation = "")
Example: playAnimation(getNode("AnimatedSprite"),"myAnimation");

getNode

Usage: Returns a node relative to the current object. Works the same as get_node in GDScript.
Syntax: getNode(name : string)
Example: getNode("Player");

setBorder

Usage: Sets the current border. Can be a direct filename (without the extension) or a name defined on borders.json.
Syntax: setBorder(border : string)
Example: setBorder("snow");

createNode

Usage: Creates a node of any native Godot type and returns it.
Syntax: createNode(name : string, type : string, position : vector)
Example: createNode("myNode", "Node2D", vec2(320,240));

reparent

Usage: Reparents a node to a new node.
Syntax: reparent(child : node, parent : node)
Example: reparent(getNode("child"), getNode("newParent"));

createText

Usage: Creates a TextObject node and returns it.
Syntax: createText(name : string, text : string, position : vec2, font : font = internal[DTM-Mono.otf])
Example: createText("myText", "Hello World!", vec2(160,120));

playSound

Usage: Plays a sound.
Syntax: playSound(sound : string)
Example: playSound("snd_noise");

playBGM

Usage: Plays audio on the background music audio stream. Should be used for things like cutscenes.
Syntax: playBGM(audio : string)
Example: playBGM("mus_home");

fadeInBGM

Usage: Fades in background music.
Syntax: fadeInBGM();

fadeOutBGM

Usage: Fades out background music.
Syntax: fadeOutBGM();

loadRoom

Usage: Changes the current room.
Syntax: loadRoom(room : string)
Example: loadRoom("room_flowey");

loadAudio

This function currently has no use in other functions, but can be used with set().

Usage: Loads and returns an audio file, starting directly from the Audio folder.
Syntax: loadAudio(path : string)
Example: loadAudio("Sounds/snd_noise");

moveCharacter

Usage: Moves a Character object. Intended to be used for cutscenes.
Syntax: moveCharacter(char : node, direction : vector, tiles : number)
Example: moveCharacter(getNode("Layer1/plr"), DIR_UP, 2);

getFlag

Usage: Returns a flag value.
Syntax: getFlag(flag : string)
Example: setFlag("test_flag");

setFlag

Usage: Sets the value of a flag.
Syntax: setFlag(flag : string, value : any)
Example: setFlag("test_flag", 45);

encounter

Usage: Starts an encounter.
Syntax: encounter(filename : string)
Example: encounter("dummy");

getRoomNode

Usage: Returns the current scene root.
Syntax: getRoomNode()

loadTexture

This function currently has no use in other functions, but can be used with set().

Usage: Loads and returns an image file, starting directly from the Sprites folder.
Syntax: loadTexture(filename : string)
Example: loadTexture("spr_test");

function

Usage: TBA
Syntax: TBA
Example: TBA

this document is unfinished! please be patient :3