Questions using events - PowerPoint PPT Presentation

1 / 43
About This Presentation
Title:

Questions using events

Description:

In the world details pane, go to properties, and click create new variable. ... Click on the function tab, create a new function, name it possibleChoices, and ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 44
Provided by: deborah83
Category:

less

Transcript and Presenter's Notes

Title: Questions using events


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, go to properties, and
    click create new variable.
  • Name it correctAnswer. Select type Object.

5
  • Click create new variable again.
  • Name this one userAnswer, and 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, and 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 Which animal says meow? Click on that
    animal. Set the duration to 2 seconds.
  • 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,
    and 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 part of the
    While loop.
  • Step 4 In the drop down menu, select
  • correctAnswer !, expressions, and
    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 to the end of quiz1 method.
  • Select 2 seconds in the drop down menu.

14
  • Repeat Part 1, steps 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
(No Transcript)
16
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.

17
Playing your world
  • Click on the properties tab in the world details.
  • Play your world. The correctAnswer variable
    changes to cat after the teacher asks her
    question.

18
Part 2 Storing the users answer
  • We will now write code to store the users
    answer.
  • Click on the function tab, create a new function,
    name it possibleChoices, and select type Boolean.
    Boolean returns true or false.

19
Create a new parameter
  • Click on create new parameter in the
    world.possibleChoices function.
  • Name it objClicked. Select type Object.

20
  • Step 1Drag an If/else from the bottom of the
    window and drag it 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, and the entire cat.
  • See the screenshot on the next slide for an
    illustration.

21
  • Resulting code

22
  • Step 3 drag Return from the bottom of the window
    on top of the Do Nothing under the If.
  • Click on the ltNonegt beside return and select true.

23
  • 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 objClicked, bunny, and the
    entire bunny.
  • Resulting code

24
  • Step 3 Drag in Return under If objClicked
    Bunny. 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

25
  • Drag Return on top of the final Do Nothing.
    Select false in the drop down menu.
  • Dont forget to set the final Return to false.

26
Compare method
  • In the world details pane, click on the method
    tab. Click create new method. Name it compare.
  • Drag an If/Else from the bottom of the window,
    and select true. Click on the functions tab and
    drag the function possibleChoices on top of the
    true.

27
  • Click on the properties tab in the world details
    pane.
  • Drag userAnswer on top of the ltNonegt next to
    world.possibleChoices.

28
  • Drag another If/Else on top of the Do Nothing
    underneath the If, and select true. Then drag
    userAnswer onto the true, select userAnswer!,
    expressions, and world.correctAnswer.
  • Resulting Code

29
  • 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.

30
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. Thats right
  • Drag the userAnswer into the Do together and
    select turn left 1 revolution.
  • See the screenshot on the next slide for an
    illustration.

31
(No Transcript)
32
  • 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 seconds.
  • See the screenshot on the next slide for the
    complete method.

33
(No Transcript)
34
ChooseObject method
  • Next, write the method to call this compare
    method. Click create new method in the world
    details pane.
  • Name it chooseObject.
  • Click create new parameter in this method. Name
    it objClicked. Select type Object.

35
  • Click on the properties tab in the world details
    pane. Drag userAnswer into the chooseObject
    method. Select set value, expressions, and
    objClicked.

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

37
Calling the chooseObject method Making an event
  • In the events editor, click on create new event,
    and select When the mouse is clicked on
    something.

38
  • Click on the methods tab in the world details
    pane.
  • Drag the chooseObject method on top of the
    Nothing in the event.

39
  • In the drop down menu, select expressions, and
    object under mouse cursor.
  • Here is the complete event

40
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.

41
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)

42
Further practice
  • Drag the camera set point of view instruction
    into your world.my first method. Select Dummy
    Objects, and 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.

43
Recap
  • Two world-level property variables are used to
    store the correct answer and the users answer.
  • To begin, the correct answer is set. Until the
    users 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 users
    answer to the correct answer (world.compare) .
Write a Comment
User Comments (0)
About PowerShow.com