Parent here, trying to help kid... We are trying to make a "timed ask" coming from the stage. In parallel, it launches (1) a custom block that displays and increments a countdown timer from the current (timer) sprite and (2) tells the stage to ask a question. Whichever one completes first is intended to stop the other. It works great, however we wanted to make it a reporter instead of setting timer_answer. We can't find a way (other than triggering outside event code) to make it wait for one (but not both) of the parallel events to complete. There must be a way to do this...
My apologies. I updated the code slightly in another thread, which you can feel free to delete, since you all have responded here. Here's the new code:
We've tried to use "wait until" (as you see here), but the "stops" are stopping the outer thread as well. Actually, we can even live without it being a reporter... however, it's just unusable as is because when this block has another block following, it doesn't wait for the earlier of the two events. It passes control immediately to the next block after it. This is basically an "ask or timeout" block, and we want it to wait until one of those occurs. If you could even just help us with the wait issue, that would be fantastic!
I'm also re-reading the continuations chapter of the manual. I have to admit, that while I'm familiar with certain aspect of functional programming (e.g., map, filter, reduce, function factories, python "with" blocks, etc.) I'm having difficulty applying the text in that chapter to this problem. I'll keep reading while you're experimenting. If I come up with anything, I'll post a further reply.
This is very helpful. Didn't know the hidden sprite trick or the script pic trick!
If I have an actual sprite "countdown" graphic sequence in place of the wait (that's what my original timer block was), how do I factor that in? What if wait is 10 sec but "ask" is answered in three? How do I make the countdown stop and hide and the outer custom block to return control? I want the game to continue early and the countdown to disappear if it's answered early...
To be clear, I don't want to change the timer block above. I only include it for reference. I want to try to encapsulate all the ask stuff (which is one user of, but not the only user of timer) into the customized ask block pictured at the top of this post. Thanks!
Thanks so much for this. I like this answer, but I just can't get it to work. The "stop other scripts in sprite" seems to be stopping the final two commands before they are executed. It never reports for me. Do you know why that would be?
I'm assuming the Q in "ask Q for ..." is just the name of the sprite containing the block, correct?
That's why joecooldoo wants you to use a separate sprite for the two processes, so the STOP block won't stop the main script. (Remember that LAUNCH starts a new thread running your launched script, so the script that calls LAUNCH is an "other script" relative to those launched threads.)
I'm trying joecooldoo solution now. Will report back.
Would you mind posting the non-functional code for the continuation method? Pretty please? I know it won't work if there's a bug... I just want to see if I'm thinking along the right track. I've been reading and re-reading the continuations section in the manual to see if I could come up with anything.
It seems to me this should be a generalizable problem. I want to launch 2 (or n) independent threads a la "do in parallel", but I want to wait only until the FIRST returns, and then stop all remaining threads.
"Do in parallel and wait" wants to wait for all of them. I was thinking of trying to first solve this general problem with continuations and then try to apply it to the "ask with countdown animation" issue... but I will keep thinking.
Thanks so much for continuing to look into it. My kid is very excited that there are so many nice people (including folks on the development team) willing to lend a hand. What a great community!
This isn't a 25-words-or-less question. I mean, I can define it quickly: The continuation of a block that's part of a script is the work that remains to be done after that block finishes. But to understand the implications, you should read section X of the manual.