NT Script: Difference between revisions

Jump to navigation Jump to search
665 bytes added ,  21:49, 24 February 2019
no edit summary
No edit summary
Line 29: Line 29:
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 61: Line 61:
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 218: Line 234:
| 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 232: Line 248:
|}
|}


=== 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 245: Line 261:
| 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" |
|-
| 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.
|-
|-
| 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.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" |
|-
|-
| push_back(vector, ...) || || Adds Arg.2 (and every item after) to the end of the vector. Deprecated by the += operator.
| 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" |
|-
|-
| remove(vector, ...) || || Loops through the vector and deletes the items matching the Args.
| my_list.Remove(...) || || Loops through the list 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.
| 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" |
|-
|-
| swap(vector, number, number) || || Swaps the entries's position at Arg.2 and Arg.3 in the Arg.1 vector.
| my_list.Swap(number, number) || || Swaps the entries's position at Arg.1 and Arg.2 in my_list.
|-
|-
| 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.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" |
|-
|-
| find(vector, var) || var || Searches the Arg.1 vector for Arg.2, returns 0 if not found.
| 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" |
|-
|-
| length(vector) || number || Returns the length of the vector. (amount of indices)
| length(list) || number || Returns the length of the list. (amount of indices)
|-
|-
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
|-
|-
| implode(vector, string) || string || This will join the vector(Arg.1) in a string separating the indices with the separator(Arg.2) and returns that string.
| 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 296: Line 308:
| 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" |
Line 319: Line 331:
  '''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
   
   
  '''HUMAN''' = 1
  '''languages.HUMAN''' = 1
  '''MONKEY''' = 2
  '''languages.MONKEY''' = 2
  '''ALIEN''' = 4
  '''languages.ALIEN''' = 4
  '''ROBOT''' = 8
  '''languages.ROBOT''' = 8
  '''SLIME''' = 16
  '''languages.SLIME''' = 16
  '''DRONE''' = 32
  '''languages.DRONE''' = 32
    
    
  '''$robot''' = "robot"
  '''filter_types.robot''' = "robot"
  '''$loud''' = "yell"
  '''filter_types.loud''' = "yell"
  '''$emphasis''' = "italics"
  '''filter_types.emphasis''' = "italics"
  '''$wacky''' = "sans"
  '''filter_types.wacky''' = "sans"
  '''$commanding''' = "command_headset"
  '''filter_types.commanding''' = "command_headset"


== Traffic Control Systems Implementation ==
== Traffic Control Systems Implementation ==
Line 347: 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.
}


  $source  // the source of the signal
Signal information is stored in the following variables:
  $uuid    // the name of the person the AI will track if it tries to trace the transmission
 
  $content  // the content of the signal
  sig.source  // the source of the signal
  $freq    // the frequency of the signal
  sig.uuid    // the name of the person the AI will track if it tries to trace the transmission
  $pass    // determines if the signal will be broadcasted
  sig.content  // the content of the signal
$job      // the job (only for radio messages) of the operator
  sig.freq    // the frequency of the signal
  $language // the language of the signal. Can be any of HUMAN, MONKEY, ALIEN, ROBOT, SLIME or DRONE. Or a combination of them
  sig.job      // the job (only for radio messages) of the operator
  $filters  // The voice filter of the signal. Includes bolding, italics, as well as silicon and wacky fonts. '''These must be given as a vector!'''
  sig.language // the language of the signal. Can be any of HUMAN, MONKEY, ALIEN, ROBOT, SLIME or DRONE. Or a combination of them
  $say      // The verb used in a radio messages ending in "."
  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!'''
  $ask   // The verb used in messages ending in "?". Example: COMMON SERVER asks, "Why?"
  sig.say      // The verb used in a radio messages ending in "."
  $exclaim  // The verb used in a radio messages ending in "!" Note that having more exclamation points changes it to "$yell".
  sig.ask   // The verb used in messages ending in "?". Example: COMMON SERVER asks, "Why?"
  $yell   // The verb used in a radio messages ending in "!!" or more exclamation points. By default, these messages are bolded.
  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 367: Line 385:
   
   


==== 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 381: Line 399:
Examples:
Examples:


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


'''defaults''':
'''defaults''':
Line 388: Line 406:
<br>job: None
<br>job: None


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


==== signal() ====
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 401: Line 425:
Examples:
Examples:


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


'''defaults''':
'''defaults''':
Line 420: Line 444:
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 433: Line 457:
A simple chat calculator.<br>
A simple chat calculator.<br>
Type "/calc 1+1" in chat and watch the magic happen. NB: division is not implemented due to budget cuts.
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 463: Line 489:
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;
  }
  }
26

edits

Navigation menu