|SiphonScript Tutorial: Shakespearean Insult Generator
|"Thou pottle-deep spongy fen-sucked harpy !"|
|Shakespearean Insult Generator|
This insult generator script uses plain text files to serve up random
Shakespearean insults to self-afflicting souls on the web using WebSiphon.
The adjectives.txt and nouns.txt data files are in plain text format. Each line of the file contains an adjective or a noun, followed by a carriage return. The first thing to do is to read in the text files and split() them on the carriage return.
This gives us two lists, adj and n, containing all of our adjectives and nouns. To build our insult we need up to three adjectives and one noun. We'll start with the adjectives.
Choosing an adjective is simple, we use the random() function to randomly grab an adjective and then we add it to our chosen list.
As we want to have more than one adjective in our insult, we want to use a repeat ... times statement to make a up to three choices. Make sure to specify the end of your repeat loop so that only the desired code is repeated.
To insure that our insult is interesting and not repetitive, we will add some checking to make sure that each adjective selected is unique. This is a two part process. First we we can use the in comparison operator to determine if the adjective has already been used. Then we use a repeat while loop to keep choosing while the adjective is in the list. Our final adjective selection process looks like this:
Now we can build the insult.
~ To the curious: This tutorial page was authored on 9/27/97 by hippo, which was then based on a demonstration script written on 10/03/96 by creed. While listening to John Brown Body's "All Time", nnunn revived and tidied up this page due to popular demand on 11/03/04. Enjoy!
|email@example.com||Copyright © 1996-2023 Purity Software. All rights reserved.|