Give the water tracker a cheer when the goal is reached, and a video under it. A sound played from an event that's checked every tick starts again every tick; Trigger once while true plays it once, then waits until the goal isn't reached any more.
Apps cheer you on: a chime when a timer ends, a sound when you finish a level. The hard part isn't the sound, it's making it play once, at the right moment.
The water tracker from the last lesson says Goal reached! when you get to 8 glasses. Today it also cheers, and it shows a short video about where water comes from.
A Sound object holds a sound and has its own play button. Play Cheer plays it from the start.
A Video object plays a video from a link, in the browser's own player.
Turn your sound on, or use headphones.
How this lesson works: See it, Build, Check, Make it yours
See it: Try the finished thing first, so you know what you are building.
Build: Watch the short clip, then do the steps. Your app carries on from the step before.
Check: A quick check that the idea has stuck.
Make it yours: Change your app on purpose, then try it on someone.
Make your prediction first. Help opens once you've locked it in.
See itTry the finished thing first, so you know what you are building.
Try the finished app
Add glasses until you reach 8. The cheer plays once. Click Reset and do it again: it cheers again.
The video under it is NASA's The Water Cycle, one water molecule's journey from the ocean and back. Press play on it whenever you like.
Try it yourselfYour edits are saved in this browser.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 1: a cheer
+ Add object, Sound. Rename it Cheer, put it under the bar (x 229, y 330, width 342) and choose the sound Win jingle. Click its ▶ to hear it.
On the Events tab, click + Add event: Variables, Variable Glasses =Goal, with the action Cheer, Play Cheer.
Run it, add glasses until you reach 8, and listen.
A Sound object, and Play · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
A Sound called Cheer, and an event: Variable Glasses = Goal → Play Cheer.
Run your program. This ticks when your code does all of the above.
CheckA quick check that the idea has stuck.
Why does it sound like that?
Think back to the water tracker lesson: which events run every tick?
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 2: once while true
In the event that plays Cheer, click + Condition: System, Trigger once while true. Keep it last in the event.
Run it and reach 8: one cheer.
Click Reset, then reach 8 again. Does it cheer again?
Once while true means once each time the condition becomes true. Reset makes Glasses = Goal false, so the next time you reach 8 it's a new moment.
Try it yourselfYour edits are saved in this browser.
The cheer event has Trigger once while true, so it plays once when the goal is reached.
Run your program. This ticks when your code does all of the above.
CheckA quick check that the idea has stuck.
Check: Reset and Nib
The cap from the water tracker lesson keeps Glasses at 8.
Nib skipped Trigger once and put the sound somewhere else.
Nib's app cheers on every glass, not just at the goal. Click the line where Nib goes wrong.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 3: a video
+ Add object, Video. Rename it WaterVideo and put it under the cheer: x 229, y 392, width 342, height 192.
In Properties, paste this into Video link:
https://svs.gsfc.nasa.gov/vis/a010000/a010500/a010501/water_cycle_appletv_1280x720.webmhd.webm
Run it and press play on the video.
The video is The Water Cycle by NASA/Goddard Space Flight Center: public domain, so anyone may use it, but it's polite to say where it came from. App Builder shows its source under the player. Wikimedia Commons has many more videos you can link the same way.
Try it yourselfYour edits are saved in this browser.
A Video under the cheer plays NASA's The Water Cycle.
Run your program. This ticks when your code does all of the above.
Make it yoursChange your app on purpose, then try it on someone.
Make it yours: Reset stops the cheer
If someone clicks Reset while the cheer is playing, stop it: in ResetButton is clicked, add Cheer, Stop Cheer.
More ideas: a Pop sound on every glass (that one should play every click), your own sound with + Upload sound, or hide the cheer's player: untick Show a player in Cheer's properties. It still plays from events and takes no space; its credit shows under the app.
Try it yourselfYour edits are saved in this browser.
Clicking Reset also stops the cheer.
Run your program. This ticks when your code does all of the above.
Lesson done. You've finished every step you need.
Now you can
Add a sound and play it from an event.
Explain why an event with no trigger runs every tick while its condition is true.
Use Trigger once while true to make something happen once at the right moment.
Add a video from a link and say where it came from.
Students add a cheer to the water tracker: a Sound object and Play Cheer in an event about the goal. Because that event has no trigger, it runs every tick, so Play restarts the sound 60 times a second and they hear clicks or nothing. Trigger once while true fixes it: once each time the goal becomes reached. Then a Video object with NASA's The Water Cycle, and Reset stops the cheer. About 40 minutes.
I can explain why an event with no trigger runs every tick while its condition is true.
I can use Trigger once while true to make something happen once at the right moment.
I can add a video from a link and say where it came from.
Before class
This lesson starts from the finished water tracker (Level 2) and comes straight after it. Students need sound: headphones help in a busy room. Browsers play sound only after the user has clicked something, which every student will have done by the time they reach 8 glasses.
The broken version is deliberate. An event with a condition but no trigger (Variable Glasses = Goal) is checked every tick, about 60 times a second, and its actions run every tick while it's true. Play starts the sound from the beginning, so it never gets past the start. (Measured in a browser: about 60 Play calls in the second after reaching 8; with Trigger once, one.) The Goal reached! message has the same every-tick behaviour, but setting the same text again changes nothing, so nobody notices.
Trigger once while true runs once each time the conditions above it become true, then waits until they're false again. Keep it last in the event. It's the same idea as Construct's Trigger once.
The video is NASA/Goddard Space Flight Center's "The Water Cycle" (public domain, https://svs.gsfc.nasa.gov/10501), linked from NASA's site, so it needs the internet when it plays; nothing is uploaded. If NASA's site is blocked at school, any Wikimedia Commons video file page works the same way (App Builder turns the page link into the video).
Running the lesson
After Build 1, everyone reaches 8 and listens. Ask: what did you expect, what did you hear?
Why: link back to the water tracker's Every tick. Which events run every tick?
Build 2: before running, predict what happens after Reset.
The hard part (on purpose)
Hearing nothing at 8 looks like a broken sound, not a timing problem. Ask students to click the Sound object's ▶ in Design first: if that plays, the sound is fine and the question is when Play runs.
When students get stuck
No sound at all, even after Build 2. Ask: Does the ▶ on the Sound object play? Is the computer muted? Fix: Check the volume, and that Play is on Cheer (the Sound object), not another object.
It still clicks after adding Trigger once. Ask: Which event did you add it to? Fix: Add it to the event that plays Cheer, as its last condition.
It cheers on every glass. Ask: Which event is Play Cheer in? Fix: Move it out of the Add button's event into its own Glasses = Goal event with Trigger once.
The video doesn't play. Ask: Is the link pasted in full, ending in .webm? Is NASA's site blocked here? Fix: Paste the whole link; if the site is blocked, use a Wikimedia Commons video page instead.
Stretch and support
Stretch: Add a Pop sound on every glass (it should play every click, so it goes in the Add button's event) and a Stop Pop when the goal is reached. Which events should each sound be in, and why?
Support: Do Build 1 together, then let everyone hear the clicks before explaining why.
Where it leads
Next: a values journal with three screens. Trigger once comes back whenever an every-tick condition should act only once.
What each step is for
Try the finished app: Hearing the cheer play once at 8, and again only after Reset, shows the behaviour to build before building it.
Build 1: a cheer: A Sound object is like any object: it has its own properties, and an action plays it.
Why does it sound like that?: Connecting what you hear to when the event runs shows that a condition with no trigger is checked every tick, so its actions run every tick while it's true.
Build 2: once while true: Trigger once while true turns a condition that's checked every tick into a single moment: it runs when the condition becomes true, then waits until it's false again.
Check: Reset and Nib: Predicting the cheer after a Reset, and spotting Nib's cheer on every glass, separate when a condition becomes true from when an event runs.
Build 3: a video: A Video object plays a file from a link, in the browser's own player, with its source shown; nothing is uploaded.
Make it yours: Reset stops the cheer: Stop is the other half of Play: an action on the sound from any event, here the Reset button's.