1 / 43

Questions using events

Questions using events. By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 31, 2008. Loading the world. Download the starting world It is called questionEventStart.a2w Save it in a directory that you can find again,

vpankey
Télécharger la présentation

Questions using events

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Questions using events By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 31, 2008

  2. Loading the world • Download the starting world • It is called questionEventStart.a2w • Save it in a directory that you can find again, • After you have opened the file go into the "Layout" mode by clicking on the green button Add Objects (toward the middle of screen) • Click more controls. Click drop a dummy at the camera. Rename the dummy 'originalPosition.' To leave the layout mode, click done

  3. Overview • The purpose of this tutorial is to provide a template for a quiz in which the user clicks on a different object to answer each question. • We are going to create the following in this tutorial: • Two world-level property variables • Three world-level methods • One world-level function

  4. Creating property variables • In the world details pane, click ‘create new variable’ • Name it ‘correctAnswer’. Select type Object

  5. Click ‘create new variable’ again • Name this one ‘userAnswer’ select type Object • These variables will be used in each of the methods we are going to write.

  6. Quiz Method • Now, create a new world method, name it ‘quiz1’.

  7. Part 1: Writing quiz1 method • In this example world, the teacher asks each question. • Step 1: For the first question, click on the teacher in the object tree. Drag the teacher say method into the quiz1 method, select other and type in the question ”Which animal says ‘meow’?: • The next step is to store the correct answer in our correctAnswer variable. See the next slide

  8. Storing the correct answer • Step 2: Click on the properties tab in the world details pane. Drag “correctAnswer” into the “quiz1” method • In the drop down menu, select – “set value”, “cat”, “the entire cat” • See the screenshot on the next slide for an illustration

  9. Resulting Code:

  10. Step 3: Drag a while from the bottom of the window into your quiz1 method • In the drop down menu, select true

  11. Click on the properties tab in the world details pane • Drag correctAnswer on top of the true • Step 4: In the drop down menu, select “correctAnswer !=“, expressions, world.userAnswer • != means ‘does not equal’ • See the screenshot on the next slide for an illustration

  12. Resulting code

  13. Step 5: Finally, drag a wait from the bottom of the window at the end of quiz1 method • Select 2 seconds in the drop down menu

  14. Repeat Part 1,ssteps 1-5 for question 2: “Which animal hops?” • The answer is bunny. • Your resulting code should look like the screenshot on the following slide.

  15. Calling Quiz1 • Click on the world.my first method tab. • Click on the methods tab in the details pane. Drag quiz1 into world.my first method

  16. Playing your world • Click on the properties tab in the world details • Play your world. The ‘correctAnswer’ variable changes to cat

  17. Part 2: Storing the user’s answer • We will write code to store the user’s answer • Click on the function tab, create a new function, name it ‘possibleChoices’, select type Boolean. Which returns true or false

  18. Create a new parameter • Click on “create new parameter” in the function • Name it ‘objClicked’. Select type “Object”

  19. Step 1:Drag an “if/else” from the bottom of the window into the function. Select true in the drop down menu • Step 2: Drag the parameter “objClicked” onto the true. In the drop down menu, select “objClicked ==“, cat, the entire cat • See the screenshot on the next slide for an illustration

  20. Resulting code:

  21. Step 3: drag Return from the bottom of the window on top of the Do Nothing under the If • Click on the <None> beside return and select true

  22. Step 1: Drag an if/else on top of the Do Nothing under the Else • Select true in the drop down menu • Step 2: Drag the parameter objClicked on top of the true. And select ==, bunny, the entire bunny. Resulting code:

  23. Step 3: Drag in “Return.” Select true. • Repeat Part 2, steps 1-3 for T-rex. • Repeat Part 2, steps 1-3 for cow. • The rest of your nested if statements should look like this:

  24. Drag Return on top of the final Do Nothing. Select false in the drop down menu • Don’t forget to set the final Returnto false.

  25. Compare method • In the world details pane, click on the method tab. Create a new method. Name it ‘compare’ • Drag an if/else from the bottom of the window. Click on the functions tab and drag the function possibleChoices on top of the true.

  26. Click on the properties tab in the world details pane • Drag ‘userAnswer’ on top of the <None>

  27. Drag another if/else on top of the ‘Do Nothing’ underneath the ‘if’ • Resulting Code:

  28. Drag the ‘userAnswer’ property from the properties pane, on top of the ‘Do Nothing’ underneath this second If. • Select the ‘say’ method. Type “I am not the correct answer”

  29. The else • Drag a ‘do together’ from the bottom of the window into the ‘Do Nothing’ underneath the Else • Drag the teacher ‘say’ method into the code. Select other and type “Good job. That’s right” • Drag the ‘userAnswer’ into the do together and select turn left 1 revolution. • See the screenshot on the next slide for an illustration

  30. In the final ‘Else’, drag the teacher ‘say’ method into it. Select ‘other’ and type “click on the object to answer the question” • Change the duration to 1.5 • See the screenshot on the next slide for the complete method

  31. ChooseObject method • Next, write the method to call this compare method. ‘Create a new method’ in the world details pane. • Name it ‘chooseObject’ • ‘Create a new parameter’ in this method. Name it ‘objClicked’. Select type ‘object’

  32. Click on the properties tab in the world details pane. Drag ‘userAnswer’ into the ‘chooseObject’ method. Select ‘set value’, ‘expressions’, ‘objClicked’

  33. Click on the methods tab. Drag compare into the chooseObject method • This is the complete method

  34. Calling the chooseObject method: an event • In the events editor, click on “create new event”, select ‘when the mouse is clicked on something’

  35. Click on the methods tab in the world details pane. • Drag it on top of the “Nothing” in the event

  36. In the drop down menu, select “expressions”, “object under mouse cursor” • Here is the complete event:

  37. Play your world • After the teacher asks the first question, click on the cat for your answer to make sure all of your methods work • To test all of your if statements, after the teacher asks the second question, click on a wrong answer. Then click on anything in the world that is not an animal.

  38. Practice • The steps in this tutorial are useful for answering questions with the click event. • Go back to quiz1 method. Using steps 1-5 from Part 1 of this tutorial, ask these two questions: -Which animal is extinct? (the T-Rex) • Which animal can be milked? (the cow)

  39. Further practice • Drag the camera set point of view instruction into your world.my first method. Select Dummy Objects, Quiz2View • Create a new world method named quiz2. • In quiz2, ask questions about each of the shapes using the same format as quiz1. • Keep in mind that you will also have to revise your possibleChoices function in order to include the shapes

  40. Recap • Two world-level property variables are used to store the correct answer and the user’s answer • To begin, the correct answer is set. Until the user’s answer equals the correct answer, an empty while loop keeps the next question from being asked (world.quiz1) • When the user clicks on an object, a method is called to store that object as their answer (world.chooseObject), as long as they clicked on one of the choices (world.possibleChoices) • Then, a method is used to compare the user’s answer to the correct answer (world.compare)

More Related