26
edits
Monster860 (talk | contribs) 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; | |||
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!"; | |||
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(); | |||
while( | while(myGlobalVariable != 0) { | ||
myLocalVariable = 0; | |||
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. | 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) || | | 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: | ||
|} | |} | ||
=== | === 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" | | ||
|- | |- | ||
| | | 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" | | ||
|- | |- | ||
| | | 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" | | ||
|- | |- | ||
| | | 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" | | ||
|- | |- | ||
| | | 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" | | ||
|- | |- | ||
| | | 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" | | ||
|- | |- | ||
| | | 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" | | ||
|- | |- | ||
| | | 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( | | length(list) || number || Returns the length of the list. (amount of indices) | ||
|- | |- | ||
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | | | bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | | ||
|- | |- | ||
| | | 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: | | 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; | ||
''' | '''channels.common''' = 1459 | ||
''' | '''channels.science''' = 1351 | ||
''' | '''channels.command''' = 1353 | ||
''' | '''channels.medical''' = 1355 | ||
''' | '''channels.engineering''' = 1357 | ||
''' | '''channels.security''' = 1359 | ||
''' | '''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 | ||
''' | '''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 347: | Line 359: | ||
=== Realtime signal modification === | === Realtime signal modification === | ||
If the code is set to execute automatically, signals will first execute | 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.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 367: | Line 385: | ||
==== | ==== signal() ==== | ||
signal(message, frequency, source, job) | |||
Creates a signal with the following parameters. | |||
'''message''': The radio message | '''message''': The radio message | ||
Line 381: | Line 399: | ||
Examples: | Examples: | ||
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) | |||
==== | Broadcast a signal, created 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. | Sends a signal to the frequency, with the code. This works exactly like a remote signaler. | ||
Line 401: | Line 425: | ||
Examples: | Examples: | ||
remote_signal(1359, 25); | |||
'''defaults''': | '''defaults''': | ||
Line 420: | Line 444: | ||
Examples: | Examples: | ||
sig.source = "Jarsh Mellow"; | |||
mem( | mem(sig.source + "'s Mom"); // returns the value associated with the key "Jarsh Mellow's Mom". Returns null/0 if not found | ||
mem( | 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( | def process_signal(sig) { | ||
$expld1 = explode(sig.content, " "); | |||
if($expld1[1] == "/calc") | |||
{ | { | ||
$expld2 = explode($s, " | $s = $expld1[2]; | ||
broadcast($s + " = " + tostring(tonum( | $found = 0; | ||
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; | |||
} | } | ||
=== 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( | def process_signal(sig) { | ||
$explodeString = explode(sig.content, " "); | |||
if($explodeString[1] == "/8ball") | |||
{ | |||
//By Giacomand | |||
$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(sig.content, 7, length($content)+1); | |||
broadcast(signal("Magic 8-Ball... " + $content, $freq, $source, $job)); | |||
broadcast(signal($8ball + ".", $common, "Magic 8-Ball", "Magic 8-Ball")); | |||
return null; | |||
} | |||
return sig; | |||
} | } |
edits