You must register an account to edit pages.

NT Script

From /vg/station13
Jump to: navigation, search

The NT Scripting Language(NT Script, or NTSL) is a new piece of technology being pushed by NT Tech Department to standardize programming and communication of all Nanotrasen-grade electronic devices. Its syntax is a mixture of PHP, C++, and JavaScript. Most implementations of NT Script are not object-oriented and do not allow the definition of classes, instead, rely on ROBUSTTM memory management system to store entities in a dynamic data tree. NT Script does allow the in-line definition of functions, however.

It is important to note that NT Scripting should not be treated as BYOND coding. NT Scripting handles some things differently than BYOND does.

Example scripts can be found here.

Simple Guide to Using Scripts

  1. Get to the Telecommunications Control Room
  2. Open up the Telecommunications Traffic Control Console
  3. Authorize yourself access by clicking on Insert ID while holding your ID
  4. [Scan] for servers
  5. Click on a server which radio channel you wish to alter
  6. [Edit Code] to see the server's code
  7. Type your code into the window
  8. Save, Compile and Execute
  9. Close the code window
  10. Change Signal Execution to ALWAYS
  11. Congratulations, you're done!
    • Repeat steps 5 to 10 for each desired channel

101 to programming

Note: If you are familiar with other programming languages, the the syntax guide (and limitations list...) below should be enough to give you an idea of how to use NTSL.

In NTSL, like many other programming langauages, executes statements from top to bottom, left to right.

something(); // Executed first.

something_else(); // Executed second.


NTSL is case-sensitive, this means that the case of letters matter.





// All of the above examples are different.

Commenting your code is good for explaining your code or disabling certain parts of it, commented out code will be ignored entirely.

Comments can be placed with // or /*...*/.

// This is a comment.

This is a multi-line comment

After an NTSL statement, a semicolon (;) is required to "end" the statement.

something(); // Correct

broken() // Will throw a compilation error due to the lack of a semicolon.

3 primary aspects of programming are variables, operators and functions.


A variable is a "container" for a value.

Data types

There are 3 types of values in NTSL:

* number: just a number.
* string: a string of text.
* vector: A "list" of the above, more on these later.

There is also "null".

null simply means nothing, while it may seem that "" or 0 is also nothing, we still have the data that it's a string and number, respectively, just that the content of it is effectively nothing.

To define a variable, simply type the name, and end the line with a semicolon. Variables are referenced by name.

myVar; // Will create the variable "myVar".

Values can be assigned using the "=" operator:


myVar = 10;

You can also set the value on creation of the variable:

$var = 5;

To use numbers, simply type out the number like this:

myNumber = 123;

Decimals are allowed with a period:

myNumber = 1.5;

Negative values can also be defined:

myNumber = -2;

To use strings, place the text in quotes:

$text = "text";

Note that variables can only be used in the code block, and children thereof, that they are defined in.

Attempting to reference an undefined variable will give an exception when the code is ran.


A function is another section of code (user defined or built into NTSL itself).

The syntax to use a function is the following:


Functions can return values to assign to variables:

$time = timestamp();

Functions can be assigned "arguments" to influence the function's behaviour:

function(10, "text", 2);

To make your own functions, use the following syntax:

def function_name()
    // Code goes here.

To return a value in a custom function, use the "return" keyword:

def someFunction()
    return 20

A full list of all available functions is available lower in this guide.


Operators allow you to modify the value of a variable.

A common operator is =, which sets a value.

Mathematical operators such as +, -, *, /, ** (powers) are available:

myVar = 2 * 5; // 10
myVar = 4 - 1; // 3
myVar = 1 + 1; // 2
// myVar = 1 / 2; // WOULD be 0.5
// Division is currently broken in NTSL, sorry for that.
myVar = 2 ** 4 // 16

Most of the above can be combined with a = to do the equivalent of var = var [operator] x:

myVar = 2;
myVar += 2; // myVar is now at 4

myVar *= 3 // 12 now

Flow control

While the above functionality is nice, it is still restrictive.

if statements

An if statement will execute a block of code if a certain conditional is true:

myVar = 1;

    // code to execute if myVar is nonzero.

An if statement will pass if th value is "nonzero".

Nonzero is everything except 0, null, and "".

else statement

An else statement is a block of code that gets executed when its corresponding if statement does not pass:

    // Code that will be executed if the conditional passes.
    // Code that will be executed if the conditional fails.

elseif does the following:

    // Code that will be executed if the conditional passes.
        // Code that gets executed if conditional fails and conditional2 passes.

Can be written as:

    // Code that will be executed if the conditional passes.
    // Code that gets executed if conditional fails and conditional2 passes.

Of course, else if statements can be repeated forever.

The while loop

A while loop will keep repeating its code block as long as the conditional passes:

index = 5;
    index -= 1
    // Do some code, will be repeated 5 times total.

At any point in a loop, the break keyword may be used to terminate the loop.


At any point in a loop, the continue keyword may be used to go back to the loop's starting point.


The flow control examples hinted at conditionals, but only showed boolean conditionals.

Here is a list of all relational operators:

== : Equals
!=  : Does not equal
<  : Less than
>  : Greater than
<= : Less than or equal to
>= : Greater than or equal to

Relational operators can be used in if(), and elseif(), statements, which are used the following way:

if($myVariableNumber == 50) // if my number is 50
   // code block
elseif($myVariableNumber <= 30) // if not, is my number 30 or less?
   // code block
else // if not either 50 OR 30 or more, do this instead
   // code block

Syntax guide

If you're familiar with coding and want to know NTSL's syntax, you're where you need to be.

NTSL has semicolons after statements.

NTSL is case sensitive.

NTSL is procedural.

NTSL is NOT strongly typed.

Code blocks in NTSL use a C style syntax.

Functions in NTSL are defined with the def keyword:

def function_name()
    // Code goes here.

Vars in NTSL are defined by simply writing their name like this:


Values can also be assigned on creation:

myVar = 10;

Booleans do not exist, a conditional is true if the value is nonzero (not null, 0, or "").

An array in NTSL is a vector.

Vectors ARE associative (if you use that ability)


Yep you can't expect a shitty programming language in a 2D spaceman game to be decent, can you?

  • You cannot use other functions inside the argument for functions.
  • The [] operator does not exist, use the at() proc.
  • No ++ or -- operators.
  • It is relatively slow.
  • for loops are unheard of, they can be replicated with while loops though.
  • The compiler does not detect undefined variables or functions at compile time.

NT Deluxe Namespaces

Nanotrasen will constantly add new universal functions and features to NTSL, here are a few of them:


Syntax Returns Description
prob(number) number Returns nonzero is the probability succeeded. Returns zero if the probability failed.
sqrt(number) number Returns the square root of Arg.1.
abs(number) number Returns the magnitude of Arg.1.
floor(number) number Returns the Arg.1 rounded down to nearest integer.
ceil(number) number Returns the Arg.1 rounded up to nearest integer.
round(number) number Returns the Arg.1 rounded to nearest integer. 1.5 becomes 2, 1.49 becomes 1.
clamp(number, number, number) number Clamps Arg.1 between min(Arg.2) and max(Arg.3). clamp(30, -30, 25) = 25
inrange(number, number, number) number Returns 1 if Arg.1 is inbetween min(Arg.2) and max(Arg.3).
tostring(number) string Returns a sting value of the number.
rand(number, number) number Returns a random number that is inbetween min(Arg.1) and max(Arg.2).


A string is a sequence of characters. A string is defined by two quote marks.
"Hello world!" is a string.
A strings length is the amount of letters and blankspaces it contains.

Syntax Returns Description
find(string, string) string Searches the Arg.1 string for Arg.2, returns 0 if not found
length(string) number Returns the length of the string.
substr(string, number, number) string Returns a substring from Arg.1 based on start (Arg.2) to end (Arg.3). The first character has an index of 1, rather than 0 like other languages.
replace(string, string, string) string Returns a instance of the string (Arg.1) where all occurences of Arg.2 are replaced by Arg.3. NOTE: The function currently has a bug, if an empty string is passed as third argument then the resulting string will be empty.
lower(string) string Converts the string to lowercase.
upper(string) string Converts the string to uppercase.
explode(string, string) vector This will split the string(Arg.1) at every place that matches the separator(Arg.2) in to a vector. explode("Hello there young friend", " "), will produce a vector with 4 indices, "Hello", "there", "young", "friend". This is very useful for chat commands: if(at(explode($content, " "),1)=="/bot"){dostuff} will make dostuff only run if the first word was /bot.
repeat(string, number) string Repeats the string n(Arg.2) amount of times.
reverse(string) string Reverses the string.
tonum(string) number Converts the string in to a number.


Vectors are resizeable data containers for storing any form of entities inside. They are very useful for serving as lists; their members can be instantly accessed provided you have an appropriate position. People call them arrays in other languages. Vector indexes in NTSL start at 1, unlike in other languages where arrays are usually zero-indexed.

Syntax Returns Description
vector(...) vector Returns a vector with a given number of entities. You can add an infinite number of entries, or no entries at all.
at(vector, number) var Returns the element at the specified position in the vector.
at(vector, number, var) var Sets the cell at Arg.2 index in the Arg.1 vector to Arg.3.
This allows vectors to be used in a manner analogous to dictionaries in other languages. Elements can then be retrieved by index.
copy(vector, number, number) vector Returns a new vector based on Arg.1, ranging from minimum index Arg.2 to Arg.3.
push_back(vector, ...) Adds Arg.2 (and every item after) to the end of the vector. Deprecated by the += operator. the += operator is currently bugged.
remove(vector, ...) Loops through the vector and deletes the items matching the Args.
cut(vector, number, number) Cuts out entries from Arg.2 to Arg.3 in the Arg.1 vector.
swap(vector, number, number) Swaps the entries's position at Arg.2 and Arg.3 in the Arg.1 vector.
insert(vector, number, var) Inserts Arg.3 into Arg.1 at index Arg.2.
find(vector, var) var Searches the Arg.1 vector for Arg.2, returns 0 if not found.
length(vector) number Returns the length of the vector. (amount of indices)

Miscellaneous Definitions

Syntax Returns Description
pick(...) var Returns a randomly-selected entry from the parameters. Note: vector parameters will add their entries into the "raffle". The function will never return a vector.
time() number Returns the real time of the server in a number. You can then use this to see how much time has passed since the code has last been run via mem().
timestamp(format) string Returns a string of the time, formatted by the parameter. E.g: "DDD MMM DD hh:mm:ss YYYY" or "hh:mm:ss" or "DD MM YY". NOTE: Right now the function is bugged and returns the wrong time.

Prefab Variables

PI = 3.141592653;
E = 2.718281828;
SQURT2 = 1.414213562;
FALSE = 0; // true/false are just Boolean shortcuts to 0 and 1
TRUE = 1;
NORTH = 1;
SOUTH = 2;
EAST = 4;
WEST = 8;

$common = 1459
$science = 1351
$command = 1353
$medical = 1355
$engineering = 1357
$security = 1359
$supply = 1347

Traffic Control Systems Implementation

The Telecommunications system is directly tied to the TCS scripting implementation. It comes with the following functions and features.

Realtime signal modification

If the code is set to execute automatically, signals will first execute stored server code. Signal information is stored in the following variables:

$source  // the source of the signal
$content // the content of the signal
$freq    // the frequency of the signal
$pass    // determines if the signal will be broadcasted
$job     // the job (only for radio messages) of the operator


TCS also comes with the following functions (parameters may be ignored for automatic assignment):


broadcast(message, frequency, source, job)

Sends a radio signal to neighboring subspace broadcasters to broadcast with the following parameters.

message: The radio message. (If this value is empty then the output will be just a "*beep*".
frequency: The frequency to broadcast to.
source: The name of the broadcaster. If the source name is not in a server-side voice databank (voice analysis is performed every time a person speaks over a channel) the name will appear in UPPERCASE and Italicized to indicate a synthesized voice job
job: The job of the orator.


broadcast("Hello world!");

frequency: 1459
source: the server name
job: None

broadcast("HELP GRIEFF", 1459, "Burer", "Security Officer");


signal(frequency, code)

Sends a signal to the frequency, with the code. This works exactly like a remote signaler.

frequency: The frequency to send to.
code: The code to attach to the signal.


signal(1359, 25);

frequency: 1459
code: 30


mem(key, value)

Variables declared in a script expire after the script has finished executing. The mem function allows you to save persistent information to the server's memory to be retrieved by future executions of the script. Each telecommunications server contains its own separate databank, which is basically a hash table/dictionary, a data structure consisting of a set of key-value pairs. When called with just the key as an argument, mem will return the associated value. When called with two arguments, mem will set the value associated with the key. It is possible to store any kind of variables, integers, strings and even vectors.

key: A string used to identify the variable to be saved.
value: The information you want to store for future use. Can be any type.


$source = "Jarsh Mellow";
mem($source + "'s Mom");  // returns the value associated with the key "Jarsh Mellow's Mom". Returns null/0 if not found
mem($source + "'s Mom", "Lindsay Donk"); // sets the value associated with the key "Jarsh Mellow's Mom" to "Lindsay Donk".


Here are a few examples. You can find more useful snippets here.

Chat calculator

A simple chat calculator, divide doesn't work cause of some bug with the / operator.
Type "/calc 1+1" in chat and watch the magic happen.

$expld1 = explode($content, " ");
if(at($expld1, 1) ==  "/calc")
	$s = at($expld1, 2);
	$found = 0;
	if(find($s, "+") && $found == 0)
		$expld2 = explode($s, "+");
		broadcast($s + " = " + tostring(tonum(at($expld2,1)) + tonum(at($expld2,2))), $freq, "LINDSAY", "CALCULATER");
		$found = 1;
	if(find($s, "-") && $found == 0)
		$expld2 = explode($s, "-");
		broadcast($s + " = " + tostring(tonum(at($expld2,1)) - tonum(at($expld2,2))), $freq, "LINDSAY", "CALCULATER");
		$found = 1;
	if(find($s, "*") && $found == 0)
		$expld2 = explode($s, "*");
		broadcast($s + " = " + tostring(tonum(at($expld2,1)) * tonum(at($expld2,2))), $freq, "LINDSAY", "CALCULATER");
		$found = 1;
$pass = 1;

Magic 8-Ball

A simple Magic 8-Ball that will answer anyone's question.
Type in "/8ball <your question>" and you will get a magical response!

$explodeString = explode($content, " ");
if(at($explodeString, 1) ==  "/8ball")
	//By Giacomand
	$pass = 0;
	$8ball = pick("It is certain", "It is decidedly so", "Without a doubt", "Yes – definitely",
	"You may rely on it", "As I see it, yes", "Most likely", "Outlook good", "Yes", "Signs point to yes",
	"Reply hazy, try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no",
	"My sources say no","Outlook not so good","Very doubtful");
	$content = substr($content, 7, length($content)+1);
	broadcast("Magic 8-Ball... " + $content, $freq, $source, $job);
	broadcast($8ball + ".", $common, "Magic 8-Ball", "Magic 8-Ball");

Guides of /vg/station 13
New Player Guides
General Help - The Basics - Rules - A Crash Course In Roleplaying - Guide to Construction - Guide to Combat - Terminology - Shortcuts - Troubleshooting
Service Guides
Guide to Cargo Orders - Guide to Food and Drinks - Guide to Hydroponics - Guide to Beekeeping - Guide to Xenobotany - Guide to Vox Hydroponics - Guide to Cash Registers
Medical Guides
Guide to Medicine - Guide to Surgery/Autopsy - Guide to Chemistry - Guide to Virology - Guide to Genetics - Guide to Cloning
Scientific Research Guides
Guide to Research and Development - Guide to Robotics - Guide to Toxins - Guide to Telescience - Guide to Mechanic - Guide to Xenobiology - Guide To Xenoarchaeology
Engineer Guides
Guide to Engineering - Guide to Wiring - Guide to Construction - Guide to Advanced Construction - Guide to Singularity Engine - Guide to Atmospherics - Guide to Solars - Guide to Antimatter Engine (AME) - Guide to Thermoelectric Generator (TEG) - Guide to Supermatter Engine (SME) - Guide to R-UST - Guide to Space Pods - Guide to Telecommunications - Guide to Hacking - Guide to Assemblies
Security and Command Guides
Space Law - Standard Operating Procedure - Guide to Security - Guide to Forensics - Guide to Command - Chain of Command - Guide to Silicon Laws
Antagonist Guides
Guide to Traitor - Guide to Nuclear Operations - Guide to Revolution - Guide to Xenomorph - Guide to Cult of Nar-Sie - Guide to AI Malfunction - Illicit Access - Random Events
Misc Guides
Guide to Hypothermia - Makeshift weapons - Guide to Ghetto Chemistry - Races - Creatures - Guide to Paperwork - List of Pastebins specific to /vg/station - Reading Material - NTSL (Nanotrasen Scripting Language)
Admin and Coder Guides
Guide to Admin Tools - Understanding SS13 Code - Guide to Git CLI - SS13 for Experienced Programmers - Guide to Spriting - Guide to Mapping - Guide to GitHub/Merging Upstream Changes - Getting Your Pull Accepted - DM/BYOND: Undocumented Stuff