Building a Scorekeeper Alice 3 Tricks in Mini
Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) 0 -5 20 85 By Vicki Zhang Duke University Under the direction of Professor Susan Rodger June 2017
About the Mini Trivia Challenge Mini Trivia is a four-question game created by Vicki Zhang. The author explains four useful topics involved in separate tutorials: 1. scorekeeper 2. asking user for an answer This tutorial explains how to build a 3. billboard scorekeeper. Start by downloading 4. multi-layered object clicking Mini Trivia_Challenge 1 Scorekeeper_Start
Find and create a new Text. Model. Set name to score, and initial value to 0. >> To get started
Drag the text onto a clear spot (shown on next page) using the Default handle style. Resize it by - changing the data directly - or using the Resize handle style.
Tweak it to roughly this size and location. Color could be changed, if so inclined: --------------When satisfied, click on
One new Property for Score • Goal: Create a property used to store the value of current score • Purpose: To access the value easily • How: Add new property for Text. Model • Value type: whole number • Name: current. Score • Initializer: 0
>> Note that we are enabling ALL text models this property and the procedures that we will create.
After you added the current. Score property, Alice automatically creates a procedure (set. Current. Score) and a function (get. Current. Score). We will use them soon. current. Score is a property of the Text. Model, and used a parameter of this procedure
Three new Procedures for Score 1. set. Score 2. add. Score(#) 3. reduce. Score(#) Notes�� : • add. Score(5) will add 5 to the score, and reduce. Score(10) will subtract 10 from the score. • The # sign in the procedure is a placeholder demanding an input. Consider: If add. Score did not have this input, Alice would not know how much to add. This is called a parameter.
Set Score • Add Text. Model Procedure and name it set. Score • This procedure is created for the purpose of setting the content of display
Set Score Drag in the set. Value procedure >>Select “custom Text. String” >>Press “Ok” directly. The result is shown below. Then click the tiny triangle on the right and select “” + ? ? ? >> whole number >> current. Score
Set Score Completed
Add Score • **so that Alice knows how much to add** • Name the parameter how. Much >> • Create a second Procedure for the Text. Model • Name it add. Score • Add a parameter for this procedure
Add Score • Drag in the set. Current. Score procedure and select current. Score as the parameter in the dropdown menu. • We want to add to the current. Score by how. Much • The resulting formula should be: set. Current. Score to (current. Score + how. Much) • Process shown on next page.
Add Score Completed The point of add. Score is to update the value of current. Score and update the score displayed on the screen by calling set. Score.
Reduce Score • This is merely a numerically flipped version of add. Score. • Try it yourself first! • Step-by-step guide on the next slide.
Reduce Score • **so that Alice knows how much to reduce** • Name the parameter how. Much >> • Create a second Procedure for the Text. Model • Name it reduce. Score • Add a parameter for this procedure
Reduce Score • Drag in the set. Current. Score procedure and select current. Score as the parameter in the dropdown menu. • We want to subtract how. Much from the current. Score • The resulting formula should be: set. Current. Score to (current. Score-how. Much) • Process shown on next page.
Reduce Score Completed The point of reduce. Score is to update the value of current. Score and update the score displayed on the screen by calling set. Score.
Scorekeeper Completed! • Now we just have to plug in the procedures to appropriate places in the game. • You will have comments in Question A, Question C, Question D, and initialize. Event. Listeners for guidance.
Example: Question A Step 1: Go to scene and you should find the scene procedures. Select question. A procedure.
Example: Question A Step 2: Select on the left tool bar Text. Model—this. score, which is the visualized form of our scorekeeper
Example: Question A • We can now see all procedures of Text. Model on the left, including the ones we created. • Drag in add. Score into the do. Together box, either below or above the comment. • Select custom whole number and type in 10.
Example: Question A • Similarly, drag reduce. Score in. Make sure you place it at the same level of the comment, i. e. under “else” and outside of do together. • Select custom whole number and type in 5.
Try it out! • Run the game and click on the hammer, which corresponds to Question A. • Comments for Questions B, C and D are found, respectively, in initialize. Event. Listeners, question. C, question. D.
- Slides: 28