← Teacher guide

Goal reached: sound and video

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.

App Builder apps · Keep track · about 40 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Try 4 min · Build 1 10 min · Why 5 min · Build 2 6 min · Check 6 min · Build 3 5 min · Make it yours 4 min

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

  1. After Build 1, everyone reaches 8 and listens. Ask: what did you expect, what did you hear?
  2. Why: link back to the water tracker's Every tick. Which events run every tick?
  3. Build 2: before running, predict what happens after Reset.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

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

What you will seeA question to askThe fix
No sound at all, even after Build 2.Does the ▶ on the Sound object play? Is the computer muted?Check the volume, and that Play is on Cheer (the Sound object), not another object.
It still clicks after adding Trigger once.Which event did you add it to?Add it to the event that plays Cheer, as its last condition.
It cheers on every glass.Which event is Play Cheer in?Move it out of the Add button's event into its own Glasses = Goal event with Trigger once.
The video doesn't play.Is the link pasted in full, ending in .webm? Is NASA's site blocked here?Paste the whole link; if the site is blocked, use a Wikimedia Commons video page instead.

Answers to the checks

  1. Why does it sound like that?: At 8 glasses you hear clicks, or nothing, not a cheer. Why?
    Its event runs every tick, so Play keeps restarting it
    Variable Glasses = Goal isn't a trigger like 'is clicked'. It's checked every tick, and while it's true its actions run every tick. Play starts the sound from the beginning, so it never gets past the start.
  2. More clicks at 8: You reach 8, hear the cheer, then click Add a glass three more times (the cap keeps it at 8). How many more cheers?
    None: Glasses = Goal stayed true the whole time
    Glasses stays at 8, so Glasses = Goal stays true and Trigger once waits. Only after it's false (Reset) can it cheer again.
  3. Nib's cheer: Nib's app cheers on every glass, not just at the goal. Click the line where Nib goes wrong.
    line 2
    Line 2: Play Cheer is in the Add button's event, so it runs on every click that adds a glass. It belongs in an event about the goal (Glasses = Goal, once while true), or in a sub-event that checks Glasses = Goal after adding.

Solutions

One possible solution for each task. Other correct programs are fine.

Make it yours: Reset stops the cheer

{"version":1,"name":"Water tracker (sound and video)","features":{"level":2},"variables":[{"name":"Glasses","value":0},{"name":"Goal","value":8}],"screens":[{"id":"main","name":"Water","objects":[{"name":"GlassText","kind":"text","instanceVars":[],"instances":[{"id":"w1","x":229,"y":40,"w":342,"h":36,"text":"Glasses: 0 of 8","visible":true,"vars":{}}]},{"name":"AddButton","kind":"button","instanceVars":[],"instances":[{"id":"w2","x":229,"y":100,"w":342,"h":52,"text":"Add a glass","visible":true,"vars":{}}]},{"name":"ResetButton","kind":"button","instanceVars":[],"instances":[{"id":"w3","x":229,"y":170,"w":342,"h":46,"text":"Reset","visible":true,"vars":{}}]},{"name":"Message","kind":"text","instanceVars":[],"instances":[{"id":"m1","x":229,"y":240,"w":342,"h":32,"text":"","visible":true,"vars":{}}]},{"name":"BarBack","kind":"shape","instanceVars":[],"instances":[{"id":"m2","x":229,"y":290,"w":300,"h":24,"text":"","visible":true,"vars":{},"color":"#d5dae3"}]},{"name":"BarFill","kind":"shape","instanceVars":[],"instances":[{"id":"m3","x":229,"y":290,"w":300,"h":24,"text":"","visible":true,"vars":{},"color":"#2f8fdd"}]},{"name":"Cheer","kind":"sound","instanceVars":[],"instances":[{"id":"ws1","x":229,"y":330,"w":342,"h":52,"text":"","visible":true,"vars":{},"sound":"win"}]},{"name":"WaterVideo","kind":"video","instanceVars":[],"instances":[{"id":"wv1","x":229,"y":392,"w":342,"h":192,"text":"","visible":true,"vars":{},"link":"https://svs.gsfc.nasa.gov/vis/a010000/a010500/a010501/water_cycle_appletv_1280x720.webmhd.webm"}]}],"events":[{"id":"w1","else":false,"conds":[{"type":"everyTick"}],"actions":[{"type":"setText","target":"GlassText","value":"\"Glasses: \" & Glasses & \" of \" & Goal"},{"type":"setSize","target":"BarFill","prop":"w","value":"Glasses / Goal * 300"}],"children":[]},{"id":"w2","else":false,"conds":[{"type":"onClicked","target":"AddButton"}],"actions":[],"children":[{"id":"w2a","else":false,"conds":[{"type":"compareVar","var":"Glasses","op":"<","value":"Goal"}],"actions":[{"type":"addTo","value":"1","var":"Glasses"}],"children":[]}]},{"id":"w3","else":false,"conds":[{"type":"onClicked","target":"ResetButton"}],"actions":[{"type":"setVar","var":"Glasses","value":"0"},{"type":"stopSound","target":"Cheer"}],"children":[]},{"id":"w4","else":false,"conds":[{"type":"compareVar","var":"Glasses","op":"=","value":"Goal"}],"actions":[{"type":"setText","target":"Message","value":"\"Goal reached!\""}],"children":[]},{"id":"w5","else":true,"conds":[],"actions":[{"type":"setText","target":"Message","value":"\"Keep going\""}],"children":[]},{"id":"ws2","else":false,"conds":[{"type":"compareVar","var":"Glasses","op":"=","value":"Goal"},{"type":"triggerOnce"}],"actions":[{"type":"playSound","target":"Cheer"}],"children":[]}]}],"device":"web"}

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.

Exit ticket

A quiz app checks every tick whether Score = 10 and shows a pop-up. The pop-up keeps flashing. What's happening, and what's the fix?

The Score = 10 event runs every tick while it's true, so the pop-up is shown again and again. Add Trigger once while true so it shows once when Score reaches 10.

What each step is for

Where it leads

Next: a values journal with three screens. Trigger once comes back whenever an every-tick condition should act only once.