//Shakespearean Insult Generator Tutorial //Last Updated: 09/27/97 hippo //Original Design: creed 10/03/96 //Rewrite: hippo 09/27/97 //Re-rewrite: nnunn 11/03/04 //Approved Browsers: //MSIE v3.0 MacOS hippo //NetPositive BeOS hippo //Netscape v3.0 MacOS hippo sans_face = "geneva, ms sans serif"; appendFile("referrer.log", now() & "\t" & client_ip_address & "\t" & referer & "\r"); //Read in adjectives data file and spilt on //carriage returns adj = readFile(template_path & "adjectives.txt"); adj = split(adj, "\r"); //Read in nouns data file and split on //carriage returns n = readFile(template_path & "nouns.txt"); n = split(n, "\r"); //Choose from one to three unique adjectives chosenList = []; repeat random(3) times //Find an adjective we have not already used repeat while choice in chosenList choice = random(adj); end repeat; //add adjective to the list chosenList = chosenList & choice; end repeat; //Build the insult insult = "Thou " & chosenList & " " & random(n) & "!"; >>
| SiphonScript Tutorial: Shakespearean Insult Generator |
|
|---|---|
| "{insult}" | |
| Shakespearean Insult Generator | |
|---|---|
|
Topics:
|
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! |