An Embed shows a ready-made pendulum simulation, made as one web page. The page sends its period and length; the app sends it gravity. Students build the app around it with events: show the period when the page sends it, change gravity with planet buttons, and record readings in a table to answer a science question. The simulation is a component with inputs and outputs, the way real apps use parts other people made.
Someone has already made a pendulum simulation. Your job is the app around it: buttons that change it, and a table that records what it does.
An Embed shows a web page inside your app. Here the page is a pendulum simulation, made as one web file. You don't change the page: you build the app around it.
The page and your events talk by messages, each a name and one value:
The pendulum sendsperiod (how many seconds one swing takes) and length. In your events, Sim sends period runs each time it does, and Sim.period is the latest value.
It listens forgravity. Send gravity = … to Sim changes the pull on the pendulum.
The names are listed in the Embed's Properties, under Sends and Listens for. The page only ever gets values, never your events, and your app only gets values from it.
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
This is the app you'll build, open on the Run tab. Drag Length in the simulation and watch Period on the right change. Click Moon, then Record reading: a row goes into the table.
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: show the period
Add an event: Sim sends period. It's in Sim's group, with period already chosen.
Its action: Set PeriodText text to"Period: " & Sim.period & " s"
Run it and drag Length.
When the simulation sends a value · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
When Sim sends period, PeriodText shows the period.
Run your program. This ticks when your code does all of the above.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 2: change gravity
The three planet buttons are copies of one object, Planet, and each copy has its own g (look at its Properties).
Add an event: Planet is clicked.
Set variable Gravity toPlanet.g
Send gravity = Gravity to Sim (in Sim's group).
Set GravityText text to"Gravity: " & Gravity & " m/s²"
Run it. Does the pendulum swing faster or slower on the Moon?
Try it yourselfYour edits are saved in this browser.
Clicking a planet sets Gravity to its g, sends gravity to Sim and shows it in GravityText.
Run your program. This ticks when your code does all of the above.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 3: record a reading
Add an event: Record is clicked → Add a row to table Readings, with lengthSim.length, gravityGravity and periodSim.period.
Try it yourselfYour edits are saved in this browser.
Record adds a row to Readings with the length, gravity and period.
Run your program. This ticks when your code does all of the above.
CheckA quick check that the idea has stuck.
Check: what gets through?
See itTry the finished thing first, so you know what you are building.
Use your lab
Record two lengths on Earth, then the same two lengths on the Moon. Look at your table:
What makes the period longer?
If you could change the bob's weight, would it change the period? (The simulation doesn't let you, because it wouldn't.)
Try it yourselfYour edits are saved in this browser.
Make it yoursChange your app on purpose, then try it on someone.
Make it yours: start again
There's a Clear button. Make it clear the Readings table.
Add a Jupiter button: duplicate a Planet and set its g to 24.8. Or show how many readings there are with count(Readings).
Try it yourselfYour edits are saved in this browser.
Clear empties the Readings table.
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
Use a value an embedded simulation sends, with an event and its value.
Send a value to an embedded simulation from an event.
Record a simulation's results in a table and use them to answer a question.
Optional extension: an Embed shows a ready-made pendulum simulation (one web page, pendulum.html in this folder). The page sends period and length; the app sends gravity. Students build the app around it: Sim sends period shows the period (Build 1), planet buttons send gravity (Build 2), Record adds a row to Readings (Build 3). The Check shows that only the names in Sends get through. Then students use the lab to answer a science question and add a Clear button. About 45 minutes.
I can use a value an embedded simulation sends, with an event and its value.
I can send a value to an embedded simulation from an event.
I can record a simulation's results in a table and use them to answer a question.
Before class
Needs App Builder 1.13 (the Embed object and its messages, Level 4). The simulation is a single web page; the app never changes it. The page runs in a safe box: it can't see the rest of the app or anything saved in the browser, and the app only takes the message names listed in Sends, each with one plain value.
The page is the same one as App Builder's Pendulum lab sample. You can make your own for another topic: in an Embed's Properties, fill in Sends and Listens for, then Copy a prompt for an AI chat gives a prompt that asks for a page using those names. Paste the page it gives back with + Paste HTML. Use only an AI chat your school allows; check the page works before a class uses it.
The physics: a simple pendulum's period is 2π√(L/g), so it grows with length and shrinks with gravity, and doesn't depend on the bob's mass (for small swings). The page works the period out from that formula, so readings are exact; a real pendulum's would vary.
Running the lesson
Before Build 1 (whole class): open Sim's Properties. What does the simulation tell the app? What can the app tell it?
Use your lab: collect a few rows from the class on the board and look for the pattern together.
The hard part (on purpose)
Seeing the simulation as a part with inputs and outputs: point at the Sends and Listens for boxes in Sim's Properties before Build 1.
When students get stuck
Sim sends period isn't in the list. Ask: Which group are you looking in? Fix: It's in Sim's group (the object), not System. Sim must list period under Sends in its Properties.
An error says Sim hasn't sent period yet. Ask: When did the page last send a value? Fix: Run the app and wait a moment, or drag Length: the page sends its values when it starts and whenever they change.
Clicking Moon changes the text but not the swing. Ask: Is there a Send gravity action, and what does it send? Fix: Add Send gravity = Gravity to Sim after setting the variable.
Stretch and support
Stretch: Add a Sim sends length event that shows the length too. Why does the page send both, when the app could work out the period itself?
Support: Build 1 together with the clip; pairs do Builds 2 and 3.
Where it leads
Science: Year 10 physics on forces and motion. Code: the web pathway's DOM course, where pages send and receive messages in the same way.
What each step is for
Try the finished app: Using the finished lab first shows the two directions of messages before any are built: values come out of the simulation, and gravity goes in.
Build 1: show the period: A message from the page is a trigger with a value, so it's handled exactly like a click: an event, then actions that use the value.
Build 2: change gravity: Sending gravity in, and keeping a copy in a variable, shows that the app decides the inputs and the simulation does the physics.
Build 3: record a reading: Recording Sim.length and Sim.period into a table turns a live simulation into data the student can compare, which is the point of the lab.
Check: what gets through?: Asking what happens to a name the Embed doesn't list shows that the app only accepts the messages it was told to expect.
Use your lab: Collecting readings on two planets answers the question with the app the student built, so the data has a purpose.
Make it yours: start again: Adding Clear reuses a table action from earlier lessons on data that came from the simulation.