Build a viewer for three made-up creatures: click one and its name, stats and special ability appear, with bars for each stat. One Image object has three copies, each with its own object variables, and one click event shows whichever copy you clicked.
Games, shops and sports apps all show cards of things with stats. Behind them, one design is copied many times, and each copy keeps its own values.
Today's prototype shows three made-up creatures: Blaze, Tide and Zip. Click one, and its name, stats and special ability appear below.
You could make three separate Images, each with its own events. Instead you'll use one Image object with three copies. Object variables belong to the object, but each copy keeps its own values: Blaze's power and Tide's power are different numbers.
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 finished app you'll build, open on the Run tab. The event list under the app has only one event.
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: each creature's own values
The screen is made for you: three copies of one Image called Creature, Texts for the stats, and three Boxes for the bars (PowerBar, SpeedBar, DefenceBar). Click any copy: the sidebar says Creature, with 3 copies.
Click a creature. In Properties, under Object variables, add name and ability (start them empty), then power, speed and defence (start them at 0).
Click each creature in turn and fill in its own values: Blaze, Tide and Zip, numbers from 0 to 100, and an ability each. Make up the numbers, but be ready to say why each creature has them.
Object variables · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
Creature has the object variables name, power, speed, defence and ability.
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: show the clicked creature
On the Events tab: Creature is clicked.
Add Set NameText text toCreature.name
Add Set PowerText text to"Power: "&Creature.power, and the same for speed and defence.
Add Set AbilityText text to"Special: "&Creature.ability
Click each creature in the preview.
Creature.name means the clicked copy · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
Creature is clicked shows the clicked copy's name, power, speed, defence and ability.
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: bars
A full bar is 200 wide. In the same event, add PowerBar, Set PowerBar width toCreature.power / 100 * 200, and the same for the other two bars.
Try it yourselfYour edits are saved in this browser.
The same event sets each bar's width from the stat.
Run your program. This ticks when your code does all of the above.
CheckA quick check that the idea has stuck.
Check: one event, many creatures
Nib wanted the other two creatures to hide. Click the line where Nib's thinking goes wrong.
Make it yoursChange your app on purpose, then try it on someone.
Make it yours: a fourth creature, then your own set
Click a creature, then choose ⋯, Duplicate in the sidebar to make a fourth copy. Move it into the row, choose its picture, and fill in its object variables. Then run it and click it. What did you change on the Events tab? Nothing: the click event already works for any copy.
Choose your own set: made-up creatures, pets, robots, plants or anything with at least three characters. Upload your own pictures if you like. Give each one at least three stats and a weakness as well as an ability. Make the numbers fair: be ready to say why the strongest one isn't the best at everything.
Try it yourselfYour edits are saved in this browser.
Four copies of Creature, and still one click event.
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
Make several characters from one Image, each with its own values.
Explain the difference between an object, its copies and its object variables.
Use one click event that works for whichever character is clicked.
Students build a character viewer: one Creature Image with three copies, each with its own object variables, and one Creature is clicked event that shows the clicked creature's name, stats as text and bars, and ability. They predict and test that clicking picks one copy, find Nib's mistake (expecting Hide to hide every creature), add a fourth creature without changing the events, then design their own set. About 75 minutes.
I can make several characters from one Image, each with its own values.
I can explain the difference between an object, its copies and its object variables.
I can use one click event that works for whichever character is clicked.
Before class
The creatures are made up (Blaze, Tide, Zip). Students' own sets in Make should be made up or everyday things too; steer away from real people. Built-in pictures are fine; students can upload their own drawings on an Image.
Object variables are added once (they belong to the object) but filled in per copy: click a copy, then set its values in Properties.
Vocabulary (for teachers, and for students who ask): the object is like a class in other languages, each copy is an instance, and object variables are its properties.
Picking is the big idea: a condition picks the copies it's true for, and actions in that event apply only to those. App Builder picks like Construct, so this carries over to the games course.
The code checks read the object variables' names, not each copy's values, so Build 1 (each creature has its own values) is worth checking by eye.
Running the lesson
Before Build 2 (whole class, on the deck): one click event, three creatures. Click Tide: whose name shows? Ask how the app could know which creature you mean.
Build 1: check that every creature has its own values before anyone builds the event.
Check: act it out: three students are creatures, one clicks; only the clicked one obeys the next instruction.
Make it yours: ask what will need changing on the Events tab before anyone adds the fourth creature.
The hard part (on purpose)
Filling in object variables for each copy: students set the values on one creature and assume the others have them. Each copy must be clicked and filled in separately.
When students get stuck
Every creature shows the same stats. Ask: Did you fill in the values on each creature separately? Fix: Click each copy on the Design tab and set its own object variables in Properties.
Creature.power shows an error: there's no object called Creature. Ask: Is the event on the screen that has the creatures? Fix: Check the Events tab's heading names the creatures' screen.
A bar is far too long or too short. Ask: What should 100 power give? Fix: Creature.power / 100 * 200: 100 power is the full 200 width.
Stretch and support
Stretch: A comparison mode: click two creatures and show their stats side by side (hint: remember the first one's values in sidebar variables).
Support: Give pairs the object variable values filled in (open the Try it app), so they can spend the time on the event.
Where it leads
Next: Tidy up the journal (a function and an All screens event), then the challenge, a prototype of their own for a real user. In the games course, picking and copies come back with many enemies on screen.
What each step is for
Try the finished app: Clicking each creature in the finished viewer shows the move before it's built: one event, a different result for each copy.
Build 1: each creature's own values: Adding a variable to the object once, then filling it in on each copy, is what lets one event show different values later.
Build 2: show the clicked creature: One click event shows whichever copy was clicked: the click picks that copy, so Creature.name means its name.
Build 3: bars: Bars reuse the same picked values, turned into a width.
Check: one event, many creatures: The hide question and Nib's mistake test picking from the other side: an action in a picking event touches only the picked copy, not every copy.
Make it yours: a fourth creature, then your own set: Adding a creature without touching the events shows the payoff of object variables and picking; a set of their own uses the whole pattern in a new context.