NT Script: Difference between revisions

3,082 bytes added ,  09:07, 16 June 2023
m
Added additional info to the "time" function description
imported>Oranges
m (Add math operators, including a note about division)
m (Added additional info to the "time" function description)
 
(37 intermediate revisions by 12 users not shown)
Line 13: Line 13:
# ''[Edit Code]'' to see the server's code
# ''[Edit Code]'' to see the server's code
# Type your [[NTSL_Scripts|code]] into the window
# Type your [[NTSL_Scripts|code]] into the window
# ''Save'', ''Compile'' and ''Execute''
# Press ''Compile''
# Close the code window
# Close the code window
# Change Signal Execution to ''ALWAYS''
# Change Signal Execution to ''ALWAYS''
Line 28: Line 28:
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:
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; // The $ indicates that it is a variable.
  myVariable = 5;


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


  $myVariable = "Hello world!";
  myVariable = "Hello world!";




Line 60: Line 60:
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:
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();
  myGlobalVariable = getNumber();
   
   
  while($myGlobalVariable != 0) {
  while(myGlobalVariable != 0) {
      
      
     $myLocalVariable = 0;
     myLocalVariable = 0;
     $myGlobalVariable = $myLocalVariable;
     myGlobalVariable = myLocalVariable;
  }
  }
   
   
  $myLocalVariable = 50; // this is invalid; myLocalVariable does not exist in this scope
  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.
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"
You can also create associative lists.
my_list = list("a" = "something", "b" = "something else");
sig.content += my_list["a"]; // adds "something"
You can also use the [] operator on strings
some_string = "something";
sig.content += some_string[4]; // adds "e" since its the 4th character of "something"


=== Conditionals ===  
=== Conditionals ===  
Line 101: Line 117:
     // code block
     // code block
  }
  }
== Math ==
== Math ==
The math operators are for the most part pretty standard, the only one to watch out for is division which is not the expected / (as that would clash with comments in the naive ntsl parser)
The math operators are for the most part pretty standard, the only one to watch out for is division which is not the expected / (as that would clash with comments in the naive ntsl parser)
Line 110: Line 127:
  - is subtraction
  - is subtraction


  ^ is division
/ is division
 
  ^ is exponentiation


== NT Deluxe Namespaces ==
== NT Deluxe Namespaces ==
Line 148: Line 167:
| inrange(number, number, number) || number || Returns 1 if Arg.1 is inbetween min(Arg.2) and max(Arg.3).
| inrange(number, number, number) || number || Returns 1 if Arg.1 is inbetween 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.
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| tostring(number) || string || Returns a sting value of the number.
| tostring(number) || string || Returns a sting value of the number.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
| rand(number, number) || number || Returns a random integer that is inbetween min(Arg.1) and max(Arg.2).
|-
| rand(number) || number || Returns a random integer that is inbetween 0 and max(Arg.1).
|-
| rand() || number || Returns a random float that is inbetween 0 and 1.
|-
| randseed(number) || || Resets the RNG with this value.
|-
| sin(value) || number || Returns the sine of the value.
|-
|-
| rand(number, number) || number || Returns a random number that is inbetween min(Arg.1) and max(Arg.2).
|cos(value) || number || Returns the cosine of the value.
|-
|-
|asin(value) || number || Returns the arcsine of the value.
|-
|acos(value) || number || Returns the arcossine of the value.
|-
|log(value) || number || Returns the logarithm of the value.
|}
|}


Line 169: Line 209:
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| find(string, string) || string || Searches the Arg.1 string for Arg.2, returns 0 if not found
| find(string, string) || number || Returns the position of the first occurrence of Arg.2 in Arg.1 or 0 if no matches were found.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
Line 188: Line 228:
|-
|-
| upper(string) || string || Converts the string to uppercase.
| upper(string) || string || Converts the string to uppercase.
|-
| proper(string) || string || Converts the first character to uppercase, rest to lowercase.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| 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.
| explode(string, string) || list || This will split the string(Arg.1) at every place that matches the separator(Arg.2) in to a list. explode("Hello there young friend", " "), will produce a list 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.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
Line 205: Line 247:
|}
|}


=== Vector ===
=== 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.
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.
Line 218: Line 260:
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| vector(...) || vector || Returns a vector with a given number of entities. You can add an infinite number of entries, or no entries at all.
| list(...) || list || Returns a listwith a given number of entities. You can add an infinite number of entries, or no entries at all.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| at(vector, number, var) || var || Sets the cell at Arg.2 index in the Arg.1 vector to Arg.3 if Arg.3 is supplied, otherwise, returns the value located at Arg.2.
| my_list.Copy(number, number) || list || Returns a new list based on my_list, ranging from minimum index Arg.1 to Arg.2.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| copy(vector, number, number) || vector || Returns a new vector based on Arg.1, ranging from minimum index Arg.2 to Arg.3.
| my_list.Add(...) || || Adds Arg.1 (and every item after) to the end of the list. Deprecated by the += operator.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| push_back(vector, ...) || || Adds Arg.2 (and every item after) to the end of the vector. 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.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| remove(vector, ...) || || Loops through the vector and deletes the items matching the Args.
| my_list.Swap(number, number) || || Swaps the entries's position at Arg.1 and Arg.2 in my_list.
|-
| cut(vector, number, number) || || Cuts out entries from Arg.2 to Arg.3 in the Arg.1 vector.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| swap(vector, number, number) || || Swaps the entries's position at Arg.2 and Arg.3 in the Arg.1 vector.
| my_list.Insert(number, var) || || Inserts Arg.2 into my_list at index Arg.1.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| insert(vector, number, var) || || Inserts Arg.3 into Arg.1 at index Arg.2.
| my_list.Find(list, var) || var || Searches my_list for Arg.1, returns 0 if not found.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| find(vector, var) || var || Searches the Arg.1 vector for Arg.2, returns 0 if not found.
| length(list) || number || Returns the length of the list. (amount of indices)
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| length(vector) || number || Returns the length of the vector. (amount of indices)
| my_list.Join(string) || string || This will join the my_list in a string separating the indices with the separator(Arg.1) and returns that string.
|-
|-
|}
|}
Line 265: Line 307:
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| 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.
| 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.
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| 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().
| 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().
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
Line 276: Line 318:
|}
|}


=== Prefab Variables ===
===Prefab Variables===


  '''PI''' = 3.141592653;
  '''PI''' = 3.141592653;
Line 288: Line 330:
  '''WEST''' = 8;
  '''WEST''' = 8;
   
   
  '''$common''' = 1459
  '''channels.common''' = 1459
  '''$science''' = 1351
  '''channels.science''' = 1351
  '''$command''' = 1353
  '''channels.command''' = 1353
  '''$medical''' = 1355
  '''channels.medical''' = 1355
  '''$engineering''' = 1357
  '''channels.engineering''' = 1357
  '''$security''' = 1359
  '''channels.security''' = 1359
  '''$supply''' = 1347
  '''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 ==
== Traffic Control Systems Implementation ==
Line 303: Line 359:
=== Realtime signal modification ===
=== 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:
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:


  $source // the source of the signal
  sig.source   // the source of the signal
  $content // the content of the signal
  sig.uuid    // the name of the person the AI will track if it tries to trace the transmission
  $freq   // the frequency of the signal
sig.content // the content of the signal
  $pass   // determines if the signal will be broadcasted
  sig.freq     // the frequency of the signal
  $job    // the job (only for radio messages) of the operator
  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 ===  
=== Functions ===  
Line 316: Line 386:
   
   


==== broadcast() ====
==== signal() ====


  broadcast(message, frequency, source, job)
  signal(message, frequency, source, job)


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


'''message''': The radio message
'''message''': The radio message
Line 330: Line 400:
Examples:
Examples:


  broadcast("Hello world!");
  sig = signal("Hello world!");


'''defaults''':
'''defaults''':
Line 337: Line 407:
<br>job: None
<br>job: None


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


==== signal() ====
==== broadcast() ====
 
broadcast(sig)
 
Broadcast a signal, created using the signal() function
 
==== remote_signal() ====


  signal(frequency, code)
  remote_signal(frequency, code)


Sends a signal to the frequency, with the code. This works exactly like a remote signaler.
Sends a signal to the frequency, with the code. This works exactly like a remote signaler.
Line 350: Line 426:
Examples:
Examples:


  signal(1359, 25);
  remote_signal(1359, 25);


'''defaults''':
'''defaults''':
Line 369: Line 445:
Examples:
Examples:


  $source = "Jarsh Mellow";
  sig.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(sig.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".
  mem(sig.source + "'s Mom", "Lindsay Donk"); // sets the value associated with the key "Jarsh Mellow's Mom" to "Lindsay Donk".


[[Category:Guides]]
[[Category:Guides]]
Line 380: Line 456:


=== Chat calculator ===
=== Chat calculator ===
A simple chat calculator, divide doesn't work cause of some bug with the / operator.<br>
A simple chat calculator.<br>
Type "/calc 1+1" in chat and watch the magic happen.
Type "/calc 1+1" in chat and watch the magic happen. NB: division is not implemented due to budget cuts.
  $expld1 = explode($content, " ");
  def process_signal(sig) {
if(at($expld1, 1) ==  "/calc")
$expld1 = explode(sig.content, " ");
{
if($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, "*");
  $s = $expld1[2];
  broadcast($s + " = " + tostring(tonum(at($expld2,1)) * tonum(at($expld2,2))), $freq, "LINDSAY", "CALCULATER");
$found = 0;
$found = 1;
if(find($s, "+") && $found == 0)
{
$expld2 = explode($s, "+");
broadcast($s + " = " + tostring(tonum($expld2[1]) + tonum($expld2[2])), $freq, "LINDSAY", "CALCULATER");
$found = 1;
}
if(find($s, "-") && $found == 0)
  {
$expld2 = explode($s, "-");
broadcast($s + " = " + tostring(tonum($expld2[1]) - tonum($expld2[2])), $freq, "LINDSAY", "CALCULATER");
$found = 1;
}
if(find($s, "*") && $found == 0)
{
$expld2 = explode($s, "*");
broadcast($s + " = " + tostring(tonum($expld2[1]) * tonum($expld2[2])), $freq, "LINDSAY", "CALCULATER");
$found = 1;
}
  }
  }
return sig;
  }
  }
$pass = 1;


=== Magic 8-Ball ===
=== Magic 8-Ball ===
Line 412: Line 490:
Type in "/8ball <your question>" and you will get a magical response!
Type in "/8ball <your question>" and you will get a magical response!


  $explodeString = explode($content, " ");
  def process_signal(sig) {
if(at($explodeString, 1) ==  "/8ball")
$explodeString = explode(sig.content, " ");
{
if($explodeString[1] ==  "/8ball")
//By Giacomand
{
$pass = 0;
//By Giacomand
$8ball = pick("It is certain", "It is decidedly so", "Without a doubt", "Yes – definitely",
$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",
"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",
"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");
"My sources say no","Outlook not so good","Very doubtful");
$content = substr($content, 7, length($content)+1);
$content = substr(sig.content, 7, length($content)+1);
broadcast("Magic 8-Ball... " + $content, $freq, $source, $job);
broadcast(signal("Magic 8-Ball... " + $content, $freq, $source, $job));
broadcast($8ball + ".", $common, "Magic 8-Ball", "Magic 8-Ball");
broadcast(signal($8ball + ".", $common, "Magic 8-Ball", "Magic 8-Ball"));
 
return null;
}
  return sig;
  }
  }