### Basic Continuation Example Source: https://www.rivescript.com/tutorial Demonstrates using the `^` command to extend a RiveScript reply across multiple lines. The `^` command automatically joins the lines. ```RiveScript + tell me a poem - Little Miss Muffit sat on her tuffet, ^ In a nonchalant sort of way. ^ With her forcefield around her, ^ The Spider, the bounder, ^ Is not in the picture today. ``` -------------------------------- ### Basic RiveScript Begin Block Source: https://www.rivescript.com/tutorial A simple RiveScript Begin Block example demonstrating the basic structure and the `{ok}` tag for response processing. ```rivescript > begin + request - {ok} < begin ``` -------------------------------- ### RiveScript Topic Example Source: https://www.rivescript.com/tutorial This example demonstrates defining a topic named 'sorry' and its associated triggers. It shows how to use the {topic} tag to transition users into this topic, restricting available replies until the topic is exited or changed. ```rivescript + i hate you - You're really mean! I'm not talking again until you apologize.{topic=sorry} > topic sorry // This will match if the word "sorry" exists ANYWHERE in their message + [*] sorry [*] - It's OK, I'll forgive you!{topic=random} + * - Nope, not until you apologize. - Say you're sorry! - Apologize! < topic ``` -------------------------------- ### Managing User Variables with Get and Set Source: https://www.rivescript.com/tutorial Use and tags to retrieve and store user-specific variables. These tags allow for personalized interactions by remembering user details like name and age. ```RiveScript + my name is * - >Nice to meet you, . + i am # years old - >I will remember that you are years old. + what do you know about me - I know your name is and you are years old. ``` -------------------------------- ### Rivescript Triggers and Replies with Substitutions Source: https://www.rivescript.com/tutorial Demonstrates how Rivescript triggers and replies work, with examples showing how substitutions affect user input matching. ```rivescript + what is up - Not much, you? - nm, you? - Not a lot, you? + you are a bot - How did you know I'm a machine? ``` -------------------------------- ### RiveScript Begin Block for User Interview Source: https://www.rivescript.com/tutorial This RiveScript Begin Block example uses pre-processing to introduce the bot, set a 'met' variable, and redirect to a 'new_user' topic if the user is new. It then defines topics for the interview. ```rivescript > begin // If we don't know their name, set the new_user topic and continue. + request * == undefined => {topic=new_user}{ok} - {ok} < begin > topic new_user + * - Hi! I'm ! I'm a chatbot written in RiveScript.\s ^ What is your name?{topic=asked_name} < topic > topic asked_name + # - Your name is a number? + * - I only want your first name. + _ - >Nice to meet you, !{topic=random} < topic ``` -------------------------------- ### Perl RiveScript Interpreter Example Source: https://www.rivescript.com/tutorial Example of writing a RiveScript interpreter application in Perl 5. This code loads replies from a directory and allows interactive chat. ```perl #!/usr/bin/perl use strict; use warnings; use RiveScript; # Create a new RiveScript interpreter object. my $rs = RiveScript->new(); # Load a directory full of RiveScript documents. $rs->loadDirectory("./replies"); # You must sort the replies before trying to fetch any! $rs->sortReplies(); # Enter a loop to let the user chat with the bot using standard I/O. while (1) { print "You> "; chomp(my $message = ); # Let the user type "/quit" to quit. if ($message eq "/quit") { exit(0); } # Fetch a reply from the bot. my $reply = $rs->reply("user", $message); print "Bot> $reply\n"; } ``` -------------------------------- ### Rivescript Alternative with Optional Word Source: https://www.rivescript.com/tutorial This example shows an alternative that includes an optional word, demonstrating how to handle cases where the user might or might not include a specific word. ```rivescript + i (will|will not) * - It doesn't matter to me whether you or not. ``` -------------------------------- ### Set and Get User Variables in RiveScript Source: https://www.rivescript.com/tutorial Use to store user-specific information and to retrieve it. This allows the bot to remember details like the user's name or age. ```RiveScript + my name is * - >It's nice to meet you, . + what is my name - Your name is , silly! + i am # years old - >I will remember that you are years old. + how old am i - You are years old. ``` -------------------------------- ### Complete RiveScript Document with Random Replies Source: https://www.rivescript.com/tutorial This example shows a basic RiveScript document structure including a greeting and a trigger with multiple random responses. ```rivescript ! version = 2.0 + hello bot - Hello, human! + how are you - I'm great, how are you? - I'm good, you? - Good :) you? - Great! You? - I'm fine, thanks for asking! ``` -------------------------------- ### Weighted Triggers for Priority Source: https://www.rivescript.com/tutorial This example demonstrates RiveScript's weighted triggers. The 'google *' trigger is given a weight of 10, making it a higher priority match than the '* perl script' trigger when a user's message starts with 'google'. ```rivescript + google *{weight=10} - Google search: Click Here + * perl script - You need Perl to run a Perl script. ``` -------------------------------- ### Test Variable Definition with Source: https://www.rivescript.com/tutorial Use the tag to check if a variable is defined. If not, it defaults to 'undefined'. This is useful for conditional responses. ```RiveScript + do you know my name * != undefined => Yes, your name is . - No, you've never told me your name before. ``` -------------------------------- ### Call Object Macro for Hashing Source: https://www.rivescript.com/tutorial Demonstrates how to call the 'hash' object macro using the tag to get MD5 or SHA1 hashes of user input. ```rivescript + what is the md5 hash of * - The hash of "" is: hash MD5 + what is the sha1 hash of * - The hash of "" is: hash SHA1 ``` -------------------------------- ### RiveScript Begin Block for Response Formatting Source: https://www.rivescript.com/tutorial This RiveScript Begin Block example demonstrates post-processing by changing the reply formatting (sentence, uppercase, lowercase) based on the bot's 'mood' variable. ```rivescript > begin // Change the reply formatting based on the bot's mood + request * == happy => {sentence}{ok}{/sentence} * == angry => {uppercase}{ok}{/uppercase} * == sad => {lowercase}{ok}{/lowercase}... - {ok} < begin ``` -------------------------------- ### Accessing and Setting Environment Variables Source: https://www.rivescript.com/tutorial The tag retrieves or sets global environment variables. This example shows accessing a user's IP address and dynamically setting a debug mode. ```RiveScript + what is my ip - Your IP address is: + set debug mode (true|false) * == => >Debug mode set to . - You're not my master. ``` -------------------------------- ### RiveScript Interpreter Interactive Mode Source: https://www.rivescript.com/tutorial This is an example of the RiveScript interpreter's interactive mode output. It shows the bot's version, reply root, and instructions for interacting with the bot. ```text RiveScript Interpreter - Interactive Mode ----------------------------------------- RiveScript Version: 1.30 Reply Root: rstut You are now chatting with the RiveScript bot. Type a message and press Return to send it. When finished, type '/quit' to exit the program. Type '/help' for other options. You> ``` -------------------------------- ### Use Array in Trigger (Different Response) Source: https://www.rivescript.com/tutorial Another example of using the 'colors' array in a RiveScript trigger, showing a different response pattern. ```rivescript + i am wearing a (@colors) shirt - Do you really like ? ``` -------------------------------- ### Distinguishing Users with User ID Source: https://www.rivescript.com/tutorial The tag inserts the user's ID, used to keep user variables separate. This example shows distinguishing a master user. ```RiveScript ! var master = kirsle + am i your master * == => Yes, you are. Hi Kirsle! - No, is my master, and you are . ``` -------------------------------- ### Conditional Replies Based on Undefined Variables in RiveScript Source: https://www.rivescript.com/tutorial Implement conditional logic using '* == undefined =>' to provide a fallback response when a user variable has not yet been set. ```RiveScript + what is my name * == undefined => You never told me your name. - Your name is , silly! - Aren't you ? ``` -------------------------------- ### Rivescript Begin File Configuration Source: https://www.rivescript.com/tutorial Defines bot variables and substitutions in the `begin.rive` file. Substitutions modify user input before matching replies. ```rivescript ! version = 2.0 // Bot variables ! var name = Tutorial ! var age = 5 // Substitutions ! sub i'm = i am ! sub i'd = i would ! sub i've = i have ! sub i'll = i will ! sub don't = do not ! sub isn't = is not ! sub you'd = you would ! sub you're = you are ! sub you've = you have ! sub you'll = you will ! sub what's = what is ! sub whats = what is ! sub what're = what are ! sub what've = what have ! sub what'll = what will ! sub who's = who is ``` -------------------------------- ### Project Directory Structure (Windows) Source: https://www.rivescript.com/tutorial Recommended directory structure for RiveScript documents on Windows. ```bash Windows: C:\rstut ``` -------------------------------- ### Project Directory Structure (Unix/Mac) Source: https://www.rivescript.com/tutorial Recommended directory structure for RiveScript documents on Linux, Unix, and Mac OS. ```bash Unix: /home/USER/rstut Mac: /Users/USER/rstut ``` -------------------------------- ### Implement Bot Master Authentication and IP Fetching Source: https://www.rivescript.com/tutorial Implements a simple authentication system to restrict access to the bot's IP address. Users must say 'I am your master' and provide the correct password ('rivescript is awesome') to reveal their IP. ```rivescript + i am your master - Then you must know the secret password: + * % then you must know the secret password * == rivescript is awesome => Correct password! - That's not the right password. :-P + what is your ip address * == true => My IP address is: myip - You're not my master so you don't need to know! :-P ``` -------------------------------- ### Testing RiveScript Code (Windows) Source: https://www.rivescript.com/tutorial Command to test RiveScript documents from the specified directory on Windows. ```bash rivescript C:/rstut ``` -------------------------------- ### Handle Short Discussions with Previous Response Source: https://www.rivescript.com/tutorial Use the `%` command to match based on the bot's previous response. This is ideal for multi-turn conversations like knock-knock jokes. Remember that `%` lines are case-insensitive and undergo substitutions. ```rivescript + knock knock - Who's there? + * % who is there - who? + * % * who - LOL! ! That's funny! ``` ```rivescript + i have a dog - What color is it? + (@colors) % what color is it - That's a silly color for a dog! ``` -------------------------------- ### Capturing Previous Input with Botstar Source: https://www.rivescript.com/tutorial Use to capture wildcards from a previous '% Previous' line. This tag cannot be used with '+ Trigger'. ```RiveScript + i bought a new * - Oh? What color is your new ? + (@colors) % oh what color is your new * - is a pretty color for a . ``` -------------------------------- ### Windows Command Prompt Batch File Source: https://www.rivescript.com/tutorial A simple batch file to open a command prompt in the current directory. Save this as 'cmd.bat'. ```batch @echo off cmd ``` -------------------------------- ### Basic Wildcard Trigger Source: https://www.rivescript.com/tutorial A simple RiveScript trigger using a wildcard for a color, demonstrating a basic response. ```rivescript + what color is my (red|blue|green|yellow) * - Your is , silly! ``` -------------------------------- ### Define an Array Source: https://www.rivescript.com/tutorial Defines an array named 'colors' with several color options. This should be placed in the begin.rive file. ```rivescript ! array colors = red blue green yellow ``` -------------------------------- ### Formal Casing for User Variables in RiveScript Source: https://www.rivescript.com/tutorial Use the tag to store user input with proper capitalization, ensuring names are stored as proper nouns. ```RiveScript // Store the name with the correct casing + my name is * - >Nice to meet you, ! ``` -------------------------------- ### Implement Weighted Responses Source: https://www.rivescript.com/tutorial Use the `{weight}` tag to control the probability of a response being chosen. Higher weight values mean a higher chance of selection. Replies without a weight tag default to a weight of 1. ```rivescript + greetings - Hi there!{weight=20} - Hello!{weight=25} - Yos kyoco duckeb! ``` -------------------------------- ### Continuation with Explicit Space Source: https://www.rivescript.com/tutorial Shows how to use the `\s` escape sequence within a continuation to explicitly insert a space between joined lines. ```RiveScript // This one will have a space. + what are you - I am an artificial intelligence programmed\s ^ using RiveScript. ``` -------------------------------- ### Rivescript Alternatives with Single Word Choices Source: https://www.rivescript.com/tutorial Use alternatives within parentheses separated by pipes to allow a trigger to match one of several specific words. The matched alternative can be captured using ``. ```rivescript + what is your (home|office|cell) number - You can reach me at: 1 (800) 555-1234. ``` ```rivescript + i am (really|very|super) tired - I'm sorry to hear that you are tired. ``` -------------------------------- ### Basic Triggers Source: https://www.rivescript.com/tutorial Two basic RiveScript triggers are shown. The first matches 'google' followed by any characters, and the second matches any characters followed by 'perl script'. ```rivescript + google * - Google search: Click Here + * perl script - You need Perl to run a Perl script. ``` -------------------------------- ### Catch-All Trigger Source: https://www.rivescript.com/tutorial Implement a catch-all trigger using a single asterisk (*) to handle any user input not matched by more specific triggers. This prevents 'ERR: No Reply Matched' errors. ```rivescript + * - I'm not sure how to reply to that. - Try asking your question a different way. - Let's change the subject. ``` -------------------------------- ### Random Replies with {random} Source: https://www.rivescript.com/tutorial Use {random} and {/random} to select a random response from a list of options, separated by pipes. This can be combined with user variables for dynamic replies. This tag cannot be used with '+ Trigger'. ```RiveScript + hello * != undefined => {random} ^ Hello there, !| ^ Nice to see you again, !| ^ Hey, !{/random} - Hello there! - Hi there! - Hello! ``` -------------------------------- ### Retrieving and Setting Bot Variables Source: https://www.rivescript.com/tutorial The tag retrieves or sets bot variables, which are global to the interpreter instance. Use it to define characteristics like the bot's name or mood. ```RiveScript + what is your name - You can call me . + tell me about yourself - I am , a chatterbot written by . // Setting a bot variable dynamically + i hate you - Aww! You've just ruined my day. ``` -------------------------------- ### Open-Ended Triggers with Wildcards Source: https://www.rivescript.com/tutorial Use the asterisk (*) wildcard to match any sequence of characters in a user's input. Captured data can be referenced in replies using `` tags. ```rivescript + my name is * - Nice to meet you, ! + * told me to say * - Why would tell you to say ""? - Did you say "" after told you to? + i am * years old - A lot of people are years old. ``` ```rivescript + where is * - Where it belongs. - Where you left it. - Where the heart is. ``` ```rivescript + who is * - I don't know who is. ``` -------------------------------- ### Handling Repeated User Messages Source: https://www.rivescript.com/tutorial Use and tags to check for repeated user messages. to and to can access previous messages. ```RiveScript // If the user repeats the bot's previous message + - Don't repeat what I say. // If the user keeps repeating themselves over and over. + * == => That's the second time you've repeated yourself. * == => If you repeat yourself again I'll stop talking. * == => That's it. I'm not talking.{topic=sorry} - Please don't repeat yourself. // An example that uses both tags + why did you say that - I said, "", because you said, "". ``` -------------------------------- ### Apply Weight to Triggers and Replies with {weight} Source: https://www.rivescript.com/tutorial The {weight} tag controls trigger matching priority (higher weight = higher priority) or reply selection frequency (higher weight = more frequent). ```RiveScript + * or something{weight=10} - Or something. <@> + hello - Hi there!{weight=20} - Hey!{weight=10} - Howdy! ``` -------------------------------- ### Advanced Conditional Logic with Variable Comparison in RiveScript Source: https://www.rivescript.com/tutorial Use conditional statements to compare user variables with bot variables or other user variables for more complex response logic. The '^ Continuation' command can be used for multi-line conditions. ```RiveScript + my name is * * == => Wow, we have the same name!> * == undefined => >Nice to meet you! - >> ^ I thought your name was ? ``` -------------------------------- ### Rivescript Keyword Trigger with Wildcard Optionals Source: https://www.rivescript.com/tutorial Use wildcard optionals `[*]` to create triggers that match a keyword anywhere in the user's message. This allows for more flexible and context-aware responses. ```rivescript + [*] the machine [*] - How do you know about the machine!? ``` -------------------------------- ### Testing RiveScript Code (Unix/Mac) Source: https://www.rivescript.com/tutorial Command to test RiveScript documents from the specified directory on Linux, Unix, and Mac OS. ```bash rivescript rstut ``` -------------------------------- ### Rivescript Alternatives with Multiple Words and Captures Source: https://www.rivescript.com/tutorial Alternatives can be multiple words, and multiple alternatives can be used in a single trigger. `` tags capture the matched alternative, with ``, ``, etc., used for multiple captures. ```rivescript + i (like|love) the color * - What a coincidence! I that color too! - I also have a soft spot for the color ! - Really? I the color too! - Oh I too! ``` -------------------------------- ### Define RiveScript Person Substitutions Source: https://www.rivescript.com/tutorial Set up bidirectional pronoun substitutions using the `! person` command. This allows the bot to correctly interpret and respond to first- and second-person statements. ```rivescript ! person i am = you are ! person you are = i am ! person i'm = you're ! person you're = I'm ! person my = your ! person your = my ! person you = I ! person i = you ``` -------------------------------- ### Change Client Topic with {topic} Source: https://www.rivescript.com/tutorial The {topic} tag changes the user's current topic. This is useful for managing conversational flow and context. It cannot be used with '+ Trigger'. ```RiveScript + play hangman - {topic=hangman}Now playing hangman. Type "quit" to quit. > topic hangman + quit - Quitting the game.{topic=random} + * - hangman < topic ``` -------------------------------- ### Define Perl Object Macro for IP Address Source: https://www.rivescript.com/tutorial Defines a Perl object macro named 'myip' that fetches the bot's public IP address using the icanhazip.com service. It requires the LWP::Simple Perl module. ```perl > object myip perl my ($rs, $args) = @_; # Fetch the IP. use LWP::Simple; my $ip = get "http://icanhazip.com"; return $ip; < object ``` -------------------------------- ### Resetting Concatenation Mode Source: https://www.rivescript.com/tutorial Demonstrates resetting the concatenation mode to the default (`none`) using `! local concat = none`. This ensures subsequent continuations do not automatically add characters. ```RiveScript // Go back to the default concatenation mode (which doesn't insert ANY // character when joining lines) ! local concat = none ``` -------------------------------- ### Redirect User Input to Another Trigger Source: https://www.rivescript.com/tutorial Use the `@` command to redirect user input to a different trigger. This is useful for consolidating similar user intents under a single response trigger. ```rivescript + hello - Hi there! - Hey! - Howdy! + hey @ hello + hi @ hello ``` -------------------------------- ### Define Array with Multi-word Items Source: https://www.rivescript.com/tutorial Illustrates defining a RiveScript array where items can be phrases separated by pipe symbols, not just single words. ```rivescript // Single word array items ! array colors = red blue green yellow // Multiple word items ! array blues = light blue|dark blue|medium blue ``` -------------------------------- ### Specialized Wildcards for Numbers and Words Source: https://www.rivescript.com/tutorial Use '#' to match only numbers and '_' to match only single words. This allows for more precise trigger matching than the general '*' wildcard. Captured data is referenced with ``. ```rivescript + i am # years old - A lot of people are years old. + i am _ years old - Tell me that again but with a number this time. + i am * years old - Can you use a number instead? ``` -------------------------------- ### Redirect Within a Reply Source: https://www.rivescript.com/tutorial Use `{@ ... }` or `<@>` to redirect parts of a reply. `{@ }` calls the `` substitution within the current reply, while `<@>` is a shortcut for `{@ }`. ```rivescript + * or something{weight=100} - Or something. {@ } ``` ```rivescript + hello * - {@ hello} <@> ``` -------------------------------- ### Define Comprehensive Color Array with Continuations Source: https://www.rivescript.com/tutorial A detailed RiveScript array definition using continuations to list a wide variety of colors and shades, mixing space and pipe separators. ```rivescript // A lot of colors! ! array colors = red blue green yellow orange cyan fuchsia magenta ^ light red|dark red|light blue|dark blue|light yellow|dark yellow ^ light orange|dark orange|light cyan|dark cyan|light fuchsia ^ dark fuchsia|light magenta|dark magenta ^ black gray white silver ^ light gray|dark gray ``` -------------------------------- ### Call Object Macro with Source: https://www.rivescript.com/tutorial The tag is used to invoke an object macro, optionally passing arguments. The first word is the macro name. ```RiveScript // Call a macro named "reverse" and give it an argument + say * to me in reverse - reverse ``` -------------------------------- ### Rivescript Optional Syntax Source: https://www.rivescript.com/tutorial Use square brackets `[]` to define optional parts of a trigger. If the user includes the optional text, it helps match the trigger, but it is not captured by `` tags. ```rivescript + how [are] you - I'm great, you? ``` ```rivescript + what is your (home|office|cell) [phone] number - You can reach me at: 1 (800) 555-1234. ``` ```rivescript + i have a [red|green|blue] car - I bet you like your car a lot. ``` -------------------------------- ### Case Formatting with Source: https://www.rivescript.com/tutorial Tags like , , , and change the case formatting of text. capitalizes each word, capitalizes the first word of each sentence, and / convert the entire string. ```RiveScript + say * - ``` ```RiveScript + say * - ``` ```RiveScript + say * - ``` ```RiveScript + say * - ``` -------------------------------- ### Define a RiveScript Trigger and Response Source: https://www.rivescript.com/tutorial Use '! version' to declare the RiveScript specification version. Define a trigger with '+' and its corresponding response with '-'. Triggers are case-insensitive and punctuation-free. ```rivescript ! version = 2.0 + hello bot - Hello, human! ``` -------------------------------- ### Numerical Comparison for Age-Based Conditionals in RiveScript Source: https://www.rivescript.com/tutorial Utilize numerical comparison operators (<, <=, >, >=) within conditional statements to tailor responses based on numerical values like age. ```RiveScript + what am i old enough to do * == undefined => I don't know how old you are. * > 25 => You can do anything you want. * == 25 => You're old enough to rent a car with no extra fees. * > 21 => You're old enough to drink, but not rent a car. * == 21 => You're exactly old enough to drink. * > 18 => You're old enough to gamble, but not drink. * == 18 => You're exactly old enough to gamble. - You're not old enough to do much of anything yet. ``` -------------------------------- ### Continuation Without Automatic Spacing Source: https://www.rivescript.com/tutorial Illustrates that the `^` command does not automatically add spaces between continued lines. This can lead to unintended word concatenation. ```RiveScript // There will be no space between "programmed" and "using"! + what are you - I am an artificial intelligence programmed ^ using RiveScript. ``` -------------------------------- ### Use Array in Optional Source: https://www.rivescript.com/tutorial Shows how to use an array within an optional part of a RiveScript trigger. Items from arrays in optionals are not captured by tags. ```rivescript // Arrays in an optional - i just bought a [@colors] * - Is that your first ? ``` -------------------------------- ### Set RiveScript Recursion Depth Source: https://www.rivescript.com/tutorial Configure the maximum number of redirects allowed in a RiveScript reply chain using `! global depth`. This prevents infinite loops, with a default limit of 50. ```rivescript ! global depth = 50 ``` -------------------------------- ### Inline Redirection with {@} Source: https://www.rivescript.com/tutorial The {@} tag (or its alias <@>) performs an inline redirection to another trigger. It's useful for handling synonyms or correcting user input. This tag cannot be used with '+ Trigger'. ```RiveScript + your * - I think you mean to say "you are" or "you're", not "your". {@you are } ``` -------------------------------- ### Invoke Person Substitutions in RiveScript Source: https://www.rivescript.com/tutorial Use the `` tag within a RiveScript reply to apply defined person substitutions to captured data, such as `` variables. This ensures natural-sounding responses. ```rivescript + say * - Umm... "" ``` -------------------------------- ### Numeric Variable Manipulation with Source: https://www.rivescript.com/tutorial Tags like , , , and
can modify numeric user variables. If a variable is not defined, it's initialized to zero. These tags cannot be used with '+ Trigger'. ```RiveScript + give me 5 points - You have been given 5 points. Your balance is: . ``` -------------------------------- ### Enable/Disable RiveScript Debug Mode Source: https://www.rivescript.com/tutorial Use the `! global debug` command to toggle debug mode. This provides detailed output on the RiveScript interpreter's actions, useful for troubleshooting. ```rivescript ! global debug = true ! global debug = false ``` -------------------------------- ### Parser Option: Concatenate with Spaces Source: https://www.rivescript.com/tutorial Sets the parser to automatically join continuation lines with a space character (`\s`) using `! local concat = space`. This eliminates the need for manual `\s` insertion. ```RiveScript // Now change the concat mode to spaces ! local concat = space // Here we don't have to use \s like in the earlier example. + what are you - I am an artificial intelligence programmed ^ using RiveScript. ``` -------------------------------- ### Person Substitution with {person} Source: https://www.rivescript.com/tutorial The {person} tag processes person substitutions on text. It can be used directly or with the alias, which defaults to processing the argument. ```RiveScript + say * - ``` -------------------------------- ### Use Random Strings within a Reply Source: https://www.rivescript.com/tutorial The `{random}` tag allows you to insert random text within a single response. Separate alternative strings with a pipe symbol (`|`). ```rivescript + say something random - This {random}message|sentence{/random} has a random word. ``` -------------------------------- ### Use Array in Trigger Source: https://www.rivescript.com/tutorial Uses the 'colors' array in a RiveScript trigger to capture a color. The captured color is available in the tag. ```rivescript + what color is my (@colors) * - Your is , silly! - Do I look dumb to you? It's ! ``` -------------------------------- ### Retrieve Bot Variables in RiveScript Source: https://www.rivescript.com/tutorial Access bot-defined variables using the tag. This allows the bot to refer to its own properties, such as its name or age. ```RiveScript // The user can ask the bot its name too! + what is your name - You can call me . - My name is . + how old are you - I am years old. ``` -------------------------------- ### Define Perl Object Macro for Hashing Source: https://www.rivescript.com/tutorial Defines a Perl object macro named 'hash' that supports MD5 and SHA1 hashing. It requires the Digest::MD5 or Digest::SHA1 Perl modules. ```perl > object hash perl my ($rs, $args) = @_; my $method = shift @{$args}; my $string = join " ", @{$args}; # Here, $method is a hashing method (MD5 or SHA1), and $string # is the text to hash. if ($method eq "MD5") { require Digest::MD5; return Digest::MD5::md5_hex($string); } elsif ($method eq "SHA1") { require Digest::SHA1; return Digest::SHA1::sha1_hex($string); } < object ``` -------------------------------- ### Use Array Without Capturing Star Source: https://www.rivescript.com/tutorial Demonstrates using an array in a RiveScript trigger without capturing the matched item into a tag. The tag here captures the word following the array match. ```rivescript // Without parenthesis, the array doesn't go into a tag. + what color is my @colors * - I don't know what color your is. ``` -------------------------------- ### Add Random Replies to a Trigger Source: https://www.rivescript.com/tutorial To make a trigger respond with different messages each time, list multiple response lines under the trigger. The bot will randomly select one of these responses. ```rivescript + how are you - I'm great, how are you? - I'm good, you? - Good :) you? - Great! You? - I'm fine, thanks for asking! ``` -------------------------------- ### Parser Option: Concatenate with Newlines Source: https://www.rivescript.com/tutorial Configures the parser to automatically insert line breaks (`\n`) between continuation lines using `! local concat = newline`. This avoids manual `\n` insertion. ```RiveScript // Tell the parser to join continuation lines with line breaks ! local concat = newline // Now we don't need to explicitly write the \n characters every time! + tell me a poem - Little Miss Muffit sat on her tuffet, ^ In a nonchalant sort of way. ^ With her forcefield around her, ^ The Spider, the bounder, ^ Is not in the picture today. ``` -------------------------------- ### Insert Space Character with \s Source: https://www.rivescript.com/tutorial The \s escape sequence inserts a space character. It is particularly useful when extending lines of RiveScript code using the '^ Continue' command. ```RiveScript some text\s and more text ``` -------------------------------- ### Insert Line Break with \n Source: https://www.rivescript.com/tutorial The \n escape sequence inserts a line break character. This is useful for formatting multi-line output within RiveScript responses. ```RiveScript This is the first line.\nThis is the second line. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.