This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-01 22:04:09

jmpoole
New Scratcher
Registered: 2012-10-01
Posts: 2

Simple quiz

I am trying to make a simple quiz with a character asking a question and the player pressing a or b to choose an answer.  If the answer is right I want it to go to the next question but if it is wrong I want it to stop the game so the player can follow the instructions they recieve when the answer is wrong.

I am having problems sequencing things correctly.  This is the first time I have used scratch and when I try to sequence and question then a script such as "when a is pressed say: ...." everything keeps going out of order when I play the game.

Any suggestions?

Project: Bio game
Author:
Scratch: 1.4 of 30-Jun-09
History:
    2012-10-1 17:18:12    save    Bio game       
    2012-10-1 18:12:40    save    Bio game       
    2012-10-1 18:15:33    save    Bio game       
    2012-10-1 18:17:07    save    Bio game       
    2012-10-1 20:31:58    save    Bio game       
    2012-10-1 20:54:55    save    Bio game       
    2012-10-1 21:09:00    save    Bio game       
    2012-10-1 21:20:51    save    Bio game       
    2012-10-1 21:28:58    save    Bio game       
    2012-10-1 21:57:51    save    Bio game       

Totals:
    Sprites: 1
    Stacks: 7
    Unique costumes: 2
    Unique sounds: 1
--------
Sprite: Stage
  Costumes (1):
    background1 (480x360)
  Sounds (1):
    pop (0:00:00)
  No stacks.
--------
Sprite: teacher
  Costumes (1):
    costume1 (117x199)
  Sounds (0):
  Stacks (7):
    when b key pressed
        say "Correct!" for 2 secs
    end

    when a key pressed
        say "Please review link and try quiz again:http://www.tumblr.com/blog/mspoole" for 20 secs
        stop all
    end

    when b key pressed
        say "Correct!" for 2 secs
        say "Which organelle allows plants to photosynthesize? Press a for vacuole press b for chloroplast" for 30 secs
    end

    when green flag clicked
        move 0 steps
        say "Today we are going to ask some questions about cells and their organelles.  Lets see how much you all know!" for 4 secs
        say "Which organelle is responsible for protecting the DNA in the cell? Press a for nucleus, press b for cell wall." for 30 secs
    end

    when b key pressed
        say "Please review link and try the quiz again:http://www.tumblr.com/blog/mspoole" for 20 secs
        stop all
    end

    when a key pressed
        say "Correct!" for 2 secs
        say "Which organelle makes the proteins essential for the cell to function? Press a for nucleus press b for ribosome." for 20 secs
    end

    when a key pressed
        say "Please review link and try the quiz again:http://www.tumblr.com/blog/mspoole" for 20 secs
        stop all
    end

--------

Offline

 

#2 2012-10-02 03:12:27

Akorlith
Scratcher
Registered: 2012-09-19
Posts: 18

Re: Simple quiz

Welcome to Scratch!
In programming in general, you need to think like the computer. Imagine you're giving a complete and total idiot instructions. The computer knows nothing, makes no assumptions; if you don't tell the computer exactly what to do it won't do it.
In this case, you need to think. What is the first thing the teacher needs to do? Ask the question. Therefore, you need to ask the question first.

when gf clicked
say [Question 1: What is red and bad for your teeth?] for (5) secs
What then, you ask? Your players need to know what they're answering. In any TV show, before asking "A or B" they say what a and b correspond to. So, following this:
when gf clicked
say [Question 1: What is red and bad for your teeth?] for (5) secs
say [A: A brick OR B: An alarm clock] for (5) secs
So what then? Well, they're presented with two options. A or B. Only after you have told the question should you expect an answer. So, from this logic, we add the answers to the code.
when gf clicked
say [Question 1: What is red and bad for your teeth?] for (5) secs
say [A: A brick OR B: An alarm clock] for (5) secs
if < key [a v] pressed? >
say [Correct!] for (2) secs
end
if < key [b v] pressed? >
say [Wrong. Bye.] for (2) secs.
stop script
end
So you may think it's all done now. Let's have one last check, and read as a computer would. So, when the green flag is clicked:
Ask the question.
Say the answers.
If A is currently pressed, say correct and move on.
If B is currently pressed, say wrong and stop the script.
Hang on! The computer will just skip over the ifs unless we are holding either just after the answers are being presented. The computer does not kow that it has to stop for an answer, and doesn't. So we need to tell the computer not to go to the second question unless we answer a or b. How do we do that?
when gf clicked
say [Question 1: What is red and bad for your teeth?] for (5) secs
say [A: A brick OR B: An alarm clock] for (5) secs
wait until < < key [a v] pressed? > or < key [b v] pressed? > >
if < key [a v] pressed? >
say [Correct!] for (2) secs
end
if < key [b v] pressed? >
say [Wrong. Bye.] for (2) secs.
stop script
end
So now the computer waits until we press A or B, and then checks which one it is.
First question done.
It may seem complicated at first, but if you remember to think like a computer, it will seem intuitive in good time.
Thanks for reading.
Akorlith  smile

Offline

 

#3 2012-10-04 09:30:33

jmpoole
New Scratcher
Registered: 2012-10-01
Posts: 2

Re: Simple quiz

So how do i sequence three questions per level? I understand how to do one question but now I am confused how to make multiple questions flow correctly and how to make multiple levels??

Offline

 

#4 2012-10-04 09:51:01

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Simple quiz

jmpoole wrote:

So how do i sequence three questions per level? I understand how to do one question but now I am confused how to make multiple questions flow correctly and how to make multiple levels??

Here:

when gf clicked
set [questionNumber v] to [0]
add [q1] to [questions v]
add [q2] to [questions v]
add [q3] to [questions v]
add [a1a] to [answersA v]
add [a1b] to [answersB v]
add [a2a] to [answersA v]
add [a2b] to [answersB v]
add [a3a] to [answersA v]
add [a3b] to [answersB v]
broadcast [start v]

when I receive [start v]
change [questionNumber v] by (1)
if <(questionNumber) > [3]>
say [End of quiz.]
stop all
else
say (item (questionNumber) of [questions v]) for (5) secs
say (item (questionNumber) of [answersA v]) for (5) secs
say (item (questionNumber) of [answersB v]) for (5) secs
wait until < < key [a v] pressed? > or < key [b v] pressed? > >
if < key [a v] pressed? >
say [Correct!] for (2) secs
end
if < key [b v] pressed? >
say [Wrong. Next question.] for (2) secs
broadcast [start v]
end
end


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

Board footer