Mad Libs


Video Tutorial

Click here for a YouTube video of Lloyd building this project. The video has been optimized for viewing on an iPad.

(Note: For a "crystal clear" video, you may have to manually change the quality settings in YouTube to "720p HD" - just look for the gear symbol in the bottom right-hand corner of the YouTube window.)

LiveCode File for this Project

Script for the button "Create a Sentence":

 global varAdjective, varNoun, varVerb, varAdverb  
 on mouseUp  
   put line random (the number of lines in the field "adjectives") of field "adjectives" into varAdjective  
   put line random (the number of lines in the field "nouns") of field "nouns" into varNoun  
   put line random (the number of lines in the field "verbs") of field "verbs" into varVerb  
   put line random (the number of lines in the field "adverbs") of field "adverbs" into varAdverb  
   put "The "&varAdjective&" "&varNoun&" "&varVerb&" "&varAdverb&"." into line 1 of field "mysentence"  
 end mouseUp  

Bonus Idea!

The above code works great and it does a great job of demonstrating how to use some of the simple, yet powerful text processing commands of LiveCode. But, there is yet another wonderful keyword in the LiveCode dictionary - "any" - that we can use to simplify those four lines that begin with "put line...":


   put any line of field "adjectives" into varAdjective  
   put any line of field "nouns" into varNoun  
   put any line of field "verbs" into varVerb  
   put any line of field "adverbs" into varAdverb  

The keyword "any" both computes the range of lines that contain words and applies randomness.