← App Builder apps

Goal reached: sound and video

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.

How this lesson works: See it, Build, Check, Make it yours
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

  1. + 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.
  2. On the Events tab, click + Add event: Variables, Variable Glasses = Goal, with the action Cheer, Play Cheer.
  3. Run it, add glasses until you reach 8, and listen.
A Sound object, and Play · Sound on for the voiceover
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?

    At 8 glasses you hear clicks, or nothing, not a cheer. Why?

    BuildWatch the short clip, then do the steps. Your app carries on from the step before.

    Build 2: once while true

    1. In the event that plays Cheer, click + Condition: System, Trigger once while true. Keep it last in the event.
    2. Run it and reach 8: one cheer.
    3. 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.

      You reach 8, hear the cheer, then click Add a glass three more times (the cap keeps it at 8). How many more cheers?

      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

      1. + Add object, Video. Rename it WaterVideo and put it under the cheer: x 229, y 392, width 342, height 192.
      2. In Properties, paste this into Video link: https://svs.gsfc.nasa.gov/vis/a010000/a010500/a010501/water_cycle_appletv_1280x720.webmhd.webm
      3. 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.

          Now you can
          Next lesson5. A values journalBuild a journal app with three screens: pick a value you showed today, say what you did, then see every entry in a list. A variable carries your choice from one screen to the next, a list variable keeps the entries, and a List object shows them.
          For teachers

          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.

          Open the teacher guide: answers, solutions, slides and a worksheet.

          Students will be able to

          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.

          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

          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