We have seen some "programming" (via the code.org
course), discussed what programming is, and created a story telling program and an initials-drawing program in Scratch. There are still things you (or your students) can do with Scratch—more involved animation, trivia/quizzing, etc. Another is producing mad libs. For this assignment a modest amount of complexity is expected—you are being asked to produce a program that not only displays mad libs but allows the user to add data items that can be included when producing the mad libs. A general algorithm will be discussed in class and a template program provided for the high level operation of the program.
Before starting on the program you should have decided on the context or scenario for your mad lib, identified categories of words/phrases that will vary when presenting a mad lib, and produced a number of sample words/phrases for each category.
The program you plan and implement should include as many as possible of the elements identified below.
ask
block to request and accept input from the userWhen you are finished with your program you will want to share it with the class by placing it in our studio. That process involves:
I think the following approach works
It should show our class studio (PEEE_fall17) as a link and a checkmark (also as a link)
It should turn green.
You should be able to see that your project has been added to the studio.
That should be all it takes to "submit" the program. Whichever partner submitted the program should have the other partner sign in to Scratch and double check that the project is available in the studio. Don't forget that both partners need to individually complete the PAC assignment for this activity.
Note that you should always be able to get back to the project page or to the Scratch programming environment from which you can access the project page. If you joined Scratch, your projects should all be available and be saved regularly by the system.
I will be checking the programs to see if they meet the specifications (noted above). As this program are more complex than previous one, a project that meets the required specs will be considered "good" (and get a B or better). Better programs (for getting better grades) will include more categories, have commented code, appear well planned rather than the result of guess and check coding, use additional Scratch features in reasonable/appropriate ways, impress me in some other way, etc.
A substantial task for this program is putting everything together. One way to lessen the complexity for that is to divide the work among sprites (see below). It may also be the case that a special effort must be made to keep some elements together. For example if you have two categories that need to rhyme and the pick the 3rd element in the first category you will also need to pick the 3rd element in the second/rhyming category.
Instead of having one sprite control most of the program you can have several sprites do particular parts of it. For example, for getting data from the user, you could have one sprite for each word/phrase category. Each sprite would have a When this sprite is clicked
script that would request (using an ask ... and wait
block) data from the user. The data would be available via the answer
block. (Both are in the sensing palette.)
Similarly, sprites could be used to help get actions started. For example, a sprite could be clicked on and its When this sprite is clicked
script would do what is necessary to create and present a mad lib. Additionally, a different sprite could be clicked on when/if users wanted to enter their own data for one or more categories.
Such sharing of the load is useful when the sprites are not really part of some interaction. It is wise to be careful about distributing responsibility when sprites interact. It can make it difficult to understand why some particular task is not operating correctly and, thus, to fix/debug it.
join
block for recitationWhen a sprite needs to combine several pieces of information into a single line, the join
block will be required. For example, if you wanted to ask a person's name and then tell them hello, you might use code like:
ask [What's your name?] and wait say [(join[[Hello, ][answer]])
Notice that there is a space at the end of "Hello, ". If spaces are not placed in the text, it will not appear in what is said. Note that the join [][]
blocks can be nested inside each other to make long pieces of text. Doing so can get a bit confusing, so be careful when you have to use a lot ot them.
A list is a special variable that can have more than one data values. You create a list much like you create a variable—just click on Make a List in the Data palette. Once you have made/created the list, you might wish to put some data in it. That can be done in various ways.
You can put data in the list right after you create it.
Note that you can select an item in the list's data box and change it or delete it.
add [thing] to [list▼]
block
Just select whichever list you wish to add to and put the desired value in place of "thing". This would often be after asking the user for some data and then adding the response to the list (see code to the right).
Note that "adding" something to a list will cause it to be placed at the (back end/bottom) of the list.
insert [thing] at [1▼] of [list▼]
block
This block allows three selectable choices of where you can place something in a list—front/top ([1▼]
); random ([random▼]
); back/bottom ([last▼]
). But, you can put any number you wish. If you are using parallel lists you will want to make sure you place elements in both/all the lists at the same position. If you know for sure that the lists are the same length you can insert at the "last" position. Otherwise I would tend to use either the first position or second position.
Note that the answer
block was placed in the first list before asking the next questions. The answer
block always contains the "answer" to the last/most recent question that was asked.
Be aware!When you add data to the lists, the added data persists, i.e., it will be there the next time you run the program. As with sprite characteristics that will be the same as ending values when the program starts again (unless you change them), at the start of the next run, the data values will be the same as at the end of the previous run. This is mostly a good think. But, if you wanted people to be able to readily see their data used, you might want to shorten the lists before you start the program again. You can do that by hand or you can create code that will remove some of them.
One of the project specifications is that you use random list items to present the mad libs. The partial block show below illustrates one way to do this.
>The call to the madLib block is expected to indicate numeric values. We can do that with literals (just plain numbers), variables that have been set to appropriate values, or expressions that calculate values. I chose the latter. Had I used variables I would have had to calculate the value and store it in the variable, so I just used the expression I would have used.
The pick random (first) to (last)
block allows us to get a value from (including) the first value to (including) the last value. All we have to do is specify the first and last values. Since the first position in our lists is numbered 1
1 is the appropriate first value. The last value needs to be based on the number of items in the last and there is a block that produces that value length of [list▼]
$nbsp; for whatever list we choose. We just have to get the right list. Note that is we happen to pick a number that is too big, nothing will show up. It is important that we get the appropriate lists in the appropriate places.
One of the project specifications is that you use a parameterized block to present the mad libs. That will allow us to code the mad lib generally (abstractly and not have to duplicate any code (mostly). My (pretty complex) mad lib block definition block is shown.
Calling the module to present the mad lib as defined above can be done with numbers selected to indicate the original nursery rhyme (see below). Note that I do not specify numbers for each of the parallel (rhyming) lists as I want to get value in the same position for each of them which requires a single number to indicate the position for both.
And finally, calling the module with randomized values to make it a mad lib. (You probably won't be able to read it.)
Note the use of the pick random ...
block and the length of ...
value block (discussed above).
Keep the "pair programming" process in mind as you work. One person types and the other person watches and corrects, questions, etc. After a bit (at most 30 minutes) you change roles.
If you have questions about the assignment send me an e-mail or drop by my office. If you have a question while working on the assignment do the same. Keep in mind that when you encounter something you can't figure out you can/should think, explore, seek answers on google, etc. but, do not spend more than 15-30 minutes trying to overcome a particular error or problem.