Discuss Scratch

bcphysics
Scratcher
3 posts

countdown timer on ask and wait

Hello,
My son and I are designing a math game. We are trying to implement a timer, so when a question comes up the person has a set time to answer. I can't figure out an elegent way to pull this off. We have a timer that counts down to zero, and can do different things once the timer hits zero. However, nothing happens until the ask question is answered. This is the “wait” part of the ask and wait. I believe there could be a way to stop all, but I'm looking for other ideas on how to get the wait to terminate once the timer reaches 0.

Here is an example project: http://scratch.mit.edu/projects/26704820/


thanks
Doug

Last edited by bcphysics (Sept. 14, 2014 07:17:09)

drmcw
Scratcher
1000+ posts

countdown timer on ask and wait

The ask block can only be stopped by the user. The only programmatic way to end an ask box is the stop all which defeats the point here. Either just wait for the user to enter something and tell them they were out of time or don't use the ask box, write your own version e.g http://scratch.mit.edu/projects/19204741/

Last edited by drmcw (Sept. 14, 2014 07:51:10)

epicsandwich123
Scratcher
100+ posts

countdown timer on ask and wait

hi, i can't garuntee this will work but someone posted it on my discussion

define ask [string] and wait until <boolean>
set [To ask v] to (string)
broadcast [ask v]
wait until (boolean)

when I receive [ask v]
ask (ask) and wait

It will be very useful to have a block like this Perhaps I could have your advice on that?
stickfire-helper
Scratcher
24 posts

countdown timer on ask and wait

You could try having only two scripts in the sprite which asks the question:
broadcast [count down v]
ask (question :: grey) and wait
if <(answer) = (correct answer :: grey)> then
script for if answer is correct :: grey
else
script for if answer is incorrect :: grey
end

when I receive [count down v]
reset timer
repeat until <(timer) > (time allowed :: grey)
set [time remaining v] to ((time allowed :: grey) - (timer)) // this is so you can display the time remaining easily
end
stop [other scripts in sprite v] // this will cancel the ask block
script for if answer is incorrect :: grey
drmcw
Scratcher
1000+ posts

countdown timer on ask and wait

stop [other scripts in sprite v]
will not stop an ask block only stop all will. I'm afraid both solutions won't solve the problem as mentioned before.
theonlygusti
Scratcher
1000+ posts

countdown timer on ask and wait

Here ya go:

When gf clicked
set [answered? V] to [0]
Reset timer
Ask [] and wait
set [answered? V] to [1]


When gf clicked
wait (0.001) secs
set [fail v] to [0]
Wait until <<(timer) > (time limit :: custom arg)> or <(answered?) = [1]>>
If <not<(answered? = [1]>> then
set [fail v] to [1]
reset timer
stop [all v]
end

When [timer v] > [0.1]
If <(fail) = [1]> then
Say [you didn't answer the question in time] for (2) secs :: looks
end
bcphysics
Scratcher
3 posts

countdown timer on ask and wait

Thanks.

How did you get the list “answered?” into the set block for variables/lists? I only see how I can use the set block with existing variables.

cheers

Last edited by bcphysics (Sept. 21, 2014 03:12:36)

bcphysics
Scratcher
3 posts

countdown timer on ask and wait

And where did the block with “answered? = 1 >> then” come from?

thanks
TheCoolGuy555
Scratcher
2 posts

countdown timer on ask and wait

Well, I think this will work., Or maybe not.
when green flag clicked
set [Timer v] to [5 ]

Then this is the timer. Make it change by -1 overtime after a second. Then, also set it back the 5 seconds…
One example:
change [Timer v] by (-1)

…and continue taking away seconds.
ScratchModelMaker
Scratcher
100+ posts

countdown timer on ask and wait

Here ya go, I reviewed your project and saw the problem,

when green flag clicked
set [answers v] to [ ]
set [timer v] to [ ]
repeat until <<[(timer)] > [5 ]> or <<(answer) = [9 ]> >>
broadcast [ChangeTimer v]
ask [What is 6 + 3] and wait
if <(answer) = [9 ]> then
say [correct]
else
say [wrong]
end

end

Broadcast Changetimer:

when I receive [ChangeTimer v]
repeat until <<[(timer)] > [5 ]> or <<(answer) = [9 ]> >>
wait (1) secs
change [timer v] by (1)
end

Check if timer is over 5 already,

when green flag clicked
forever

if <[(timer)]> [5 ]> then

say [You didn't answer in time] for (2) secs
stop [all v]
end

end

Powered by DjangoBB