Guide to NTSL

From Bastion Station
Revision as of 06:10, 7 November 2026 by >Wiki import (Copied from https://wiki.monkestation.com/Guide_to_NTSL)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to 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 ROBUST(tm) 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.


Like any coding language, this will be a lot to learn at once. Do not be discouraged if it seems too much.


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 Log In
  4. Link the console to the tcommsat network
  5. Click which radio channel you wish to alter
  6. Type your code into the window
  7. Press Compile
  8. Congratulations! Fix errors in code
  9. Congratulations, you're done!


Syntax Guide

NT Script follows a simple-to-use syntax designed for users of all levels of programming expertise. Whitespace is ignored, semicolon break points are required, and curly brackets are required.


Variables

Variables are used to temporarily store any form of data that can be accessed somewhere else in the code. For simplicity, we'll ignore the fact that you can only use variables in children scope. Here is how you create a variable:


myVariable = 5;


You can alternatively assign the same variable a text value or a string:


myVariable = "Hello world!";


Functions

Functions can be used and defined dynamically. There are different pre-defined functions for each NTSL implementation, however the basic ones will remain the same. Here is how you use a function:


myVariable = getNumber();


In this example, myVariable is assigned whatever value getNumber() returns. Each function returns a value, even if a value return is explicitly not defined. Here are some more examples of how to use functions:


broadcast(myVariable);
broadcast("Hello world!");
broadcast("Griffing assistants in T-minus" + $myVariable + " seconds.");

// You can also define your own functions, using the def keyword:
def getNumber() {
    return 5;
}


Code Blocks

Blocks of code are called when a specific piece of code signals that it is a representation of a block of code. Variables defined in one code block cannot be applied or changed in other nonrelated code blocks; this is known as scope. For example:


myGlobalVariable = getNumber();
while(myGlobalVariable != 0) {
    myLocalVariable = 0; // myLocalVariable is defined within this block
    myGlobalVariable = myLocalVariable;
}
myLocalVariable = 50; // this is invalid; myLocalVariable does not exist in this scope


Once the interpreter reads the closing bracket, it destroys all variable definitions within the scope, therefore you cannot use any of the variables that existed in that particular block of code.


Lists

You can create new lists using list() and access elements using the [ ] operator.


my_list = list("something", "something else", "lynch the signal tech");
sig.content += my_list[1]; // adds "something"


Conditionals The while() loop in the previous example is considered a conditional because it only continues executing when the condition between the parentheses is true. The != is known as a relational operator which returns true to the interpreter if myGlobalVariable does not equal 0. It can be read as “while myGlobalVariable does not equal 0, execute the following block of code”.

Here is a list of all relational operators:

Operators

Operators that are used for math, changing variables or whatever else you want to do.

This list contains every single operator that ntsl supports by default.

Relational Operators

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

Arithmetic Operators

  • Add +
  • Subtract -
  • Multiply *
  • Divide /
  • Power of ^
  • Modulo %

Logical Operators

  • And &&
  • Or ||

Bitwise Operators

  • Bitwise And &
  • Bitwise Or |
  • Bitwise Xor `

Unary Operators

  • Logical Not !
  • Bitwise Not ~
  • Minus -

Assign Operators

  • Assign =
  • Assign BitwiseAnd &=
  • Assign BitwiseOr |=
  • Assign BitwiseXor `=
  • Assign Add +=
  • Assign Subtract -=
  • Assign Multiply *=
  • Assign Divide /=
  • Assign Power ^=
  • Assign Modulo %=

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
}


Functions

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


Number

Syntax Returns Description
prob(number) number Returns nonzero if 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 in between min(Arg.2) and max(Arg.3).
min(…) number Returns the smallest value of all arguments.
max(…) number Returns the largest value of all arguments.
tostring(number) string Returns a string value of the number.
rand(number, number) number Returns a random integer that is between min(Arg.1) and max(Arg.2).
rand(number) number Returns a random integer that is between 0 and max(Arg.1).
rand() number Returns a random float that is between 0 and 1.
randseed(number) Resets the RNG with this value.
sin(value) number Returns the sine of the value.
cos(value) number Returns the cosine of the value.
asin(value) number Returns the arcsine of the value.
acos(value) number Returns the arccosine of the value.
log(value) number Returns the logarithm of the value.


String

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) number Returns the position of the first occurrence of Arg.2 in Arg.1 or 0 if no matches were 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).
replace(string, string, string) string Returns an instance of the string (Arg.1) where all occurrences of Arg.2 are replaced by Arg.3.
lower(string) string Converts the string to lowercase.
upper(string) string Converts the string to uppercase.
proper(string) string Converts the first character to uppercase, rest to lowercase.
explode(string, string) list Splits the string (Arg.1) at every place that matches the separator (Arg.2) into a list.explode(“Hello there young friend”, ” “), will produce a list with 4 indices,”Hello”, “there”, “young”, “friend”.
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 into a number.

List

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
list(…) list Returns a list with a given number of entities. You can add an infinite number of entries, or no entries at all.
my_list.Copy(number, number) list Returns a new list based on my_list, ranging from minimum index Arg.1 to Arg.2.
my_list.Add(…) Adds Arg.1 (and every item after) to the end of the list. Deprecated by the += operator.
my_list.Remove(…) Loops through the list and deletes the items matching the Args.
my_list.Cut(number, number) Cuts out entries from Arg.1 to Arg.2 in my_list.
my_list.Swap(number, number) Swaps the entries' positions at Arg.1 and Arg.2 in my_list.
my_list.Insert(number, var) Inserts Arg.2 into my_list at index Arg.1.
my_list.Find(var) var Searches my_list for Arg.1, returns 0 if not found.
length(list) number Returns the length of the list (amount of indices).
my_list.Join(string) string Joins the my_list into a string, separating the indices with the separator (Arg.1), and returns that string.

Miscellaneous Definitions

Syntax Returns Description
pick(…) var Returns a randomly-selected entry from the parameters. Note: list parameters will add their entries into the “raffle”. The function will never return a list.
time() number Returns the real time of the server as a number. Time is in deciseconds, to convert into seconds divide by 10. 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”.


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;
  • channels.common = 1459;
  • channels.science = 1351;
  • channels.command = 1353;
  • channels.medical = 1355;
  • channels.engineering = 1357;
  • channels.security = 1359;
  • channels.supply = 1347;
  • channels.service = 1349;
  • languages.human = 1;
  • languages.monkey = 2;
  • languages.robot = 4;
  • languages.polysmorph = 8;
  • languages.draconic = 16;
  • languages.beachtongue = 32;
  • filter_types.robot = “robot”;
  • filter_types.loud = “yell”;
  • filter_types.emphasis = “italics”;
  • filter_types.wacky = “sans”;
  • filter_types.commanding = “command_headset”; ### 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 the process_signal function.


def process_signal(sig) {
    sig.content += " HONK";
     return sig; // not returning anything will cause the signal to not be broadcast.
}


Signal Information is stored in the following variables:

  • sig.source // the source of the signal
  • sig.uuid // the name of the person the AI will track if it tries to trace the transmission
  • sig.content // the content of the signal
  • sig.freq // the frequency of the signal
  • sig.job // the job (only for radio messages) of the operator
  • sig.language // the language of the signal. Can be any of HUMAN, MONKEY, ALIEN, ROBOT, SLIME or DRONE. Or a combination of them
  • sig.filters // The voice filter of the signal. Includes bolding, italics, as well as silicon and wacky fonts. These must be given as a list!
  • sig.pass // Whether the signal will be broadcasted. Is a boolean, set to 0 to stop the signal from passing.
  • sig.say // The verb used in a radio messages ending in “.”
  • sig.ask // The verb used in messages ending in “?”. Example: COMMON SERVER asks, “Why?”
  • sig.exclaim // The verb used in a radio messages ending in “!” Note that having more exclamation points changes it to “$yell”.
  • sig.yell // The verb used in a radio messages ending in “!!” or more exclamation points. By default, these messages are bolded.|


Functions

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


Signal( )

Signal(message, frequency, source, job) Creates a signal with the following parameters. * message: The radio message. * frequency: The frequency 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. Examples:


sig = signal(“Hello world!”);


Defaults: * frequency: 1459 * source: the server name * job: None

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


broadcast( )

broadcast(sig);

Broadcast a signal, using the signal( ) function.

remote_signal( )

remote_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. Example:

remote_signal(1359, 25);


defaults: frequency: 1459 code: 30

mem( )

mem(key, value);


Variables declared in a script expire after the script has finished executing (duh).
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. 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. Example:


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


Examples

Simple Job Indicator

Jobs will appear in parenthesis after names. Reccommended to add very last in script.


def process_signal(sig){
     sig.source += " ("+sig.job+")";
return sig;}


D20 Dice Roll

Will broadcast a message from “The D20” to the frequency /roll was spoken to.


def process_signal(sig){
    exp=explode(sig.content, " ");

    if(exp[1] == "/roll"){
        sig.pass=0;
        broadcast(signal(tostring(rand(1, 20)), sig.freq, "The D20"));
    }
return sig;}


Together

def process_signal(sig){
    exp=explode(sig.content, " ");

    if(exp[1] == "/roll"){
        broadcast(signal(tostring(rand(1, 20)), sig.freq, "The D20"));
    }
    sig.source += " ("+sig.job+")";
return sig;}


This page was copied from the Monkestation Wiki (original page and its history) and may not match Bastion Station.