Students build a character viewer: one Creature sprite with three animation frames, three copies (instances) each with its own instance variables, and one Mouse on object 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 an action to fade every creature), add a fourth creature without changing the event sheet, then design their own set.
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.
WorksheetOpen in PrintDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can make several characters from one sprite, each with its own values.
I can explain the difference between an object type, an instance and an instance variable.
I can use one click event that works for whichever character is clicked.
Timing
Predict 3 min · Build it 35 min · Investigate 12 min · Modify 8 min · Make 17 min
Before class
A sprite can't be clicked on its own. Insert the Mouse object (and Touch for tablets) and use Mouse, On object clicked; this is how any sprite becomes a button, and it's worth naming as a general trick.
The creatures are made up (Emberfox, Tidecrab, Mossbear). Students' own sets in Make should be made up or everyday things too; steer away from real people.
Vocabulary (for teachers, and for students who ask): the sprite is the object type (a class in other languages), each copy is an instance (an object), and instance variables are its properties.
Picking is Construct's big idea: a condition picks the instances it's true for, and actions in that event apply only to those. The games course builds on it.
These steps were written fresh for this site and have not yet been checked click by click in the current editor. Run through them once before class; Construct updates itself, so a menu name may differ slightly.
Running the lesson
Predict: ask how Construct could know which creature you mean.
Build it: check at step 7 that every creature has its own values before anyone builds the stats area.
Investigate: act it out: three students are creatures, one clicks; only the clicked one obeys the next instruction.
Modify: ask for a prediction before anyone opens the event sheet.
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.
Think, pair, share(start) A game's character select screen has 20 characters. Did someone write 20 separate click events? How else could it work?
What's the same about every character card?
What's different about each one?
One design (object type), many copies (instances), each with its own details (instance variables). One event that reads whichever copy was clicked.
Be the creatures(investigate, 5 min)
Three students stand at the front, each holding a card with a name and three stats. You "click" one by pointing. Read out the event's actions ("Creature: hold up your power card", "Creature: sit down"). Only the picked student acts.
On object clicked picks one instance; the event's actions apply to it alone.
The hard part (on purpose)
Filling in instance variables for each copy: students set the values on one creature and assume the others have them. Each copy must be selected and filled in separately.
When students get stuck
What you will see
A question to ask
The fix
Clicking a creature does nothing.
Is the Mouse object in the project, and does the event use Mouse, On object clicked?
Insert Mouse (Insert new object, Mouse), then make the event from Mouse, not from the sprite.
Every creature shows the same stats.
Did you fill in the values on each creature separately?
Select each copy on the layout and set its own instance variables in Properties.
All three creatures look the same.
What's each copy's Initial frame?
Set 0, 1 and 2, and animation Speed to 0.
Answers to the checks
whose name shows?: Three copies of the Creature sprite have the instance variable name: Emberfox, Tidecrab and Mossbear. The event is: Mouse on object clicked (Creature) → set NameText to Creature.name. You click the Tidecrab. What does NameText show? Tidecrab. On object clicked picks the copy you clicked, so for the rest of that event Creature.name means that copy's name.
Try the finished app: Click each creature in turn. One event shows all three.
One click event shows whichever creature you click, because the click picks that copy.
Which ones fade?: You add one more action to the click event: Creature, set opacity to 40 (faded). You click the Mossbear. Which creatures fade? Only the Mossbear On object clicked picks the copy you clicked. Every Creature action in that event applies to the picked copy only.
Find Nib's mistake: Nib wanted the other two creatures to fade. Click the line where Nib's thinking goes wrong. line 3 Line 3: in this event the click has picked the Tidecrab, so Creature, set opacity only fades the Tidecrab. To fade the others, you'd first set every creature faded in an event that doesn't pick, then set the clicked one back.
Why instance variables?: Why use instance variables here, not global variables? Each creature needs its own values; a global holds one A global variable holds one value for the whole app. Each creature needs its own power, speed and so on, so they're instance variables: same names, different values in each copy.
Predict the change: You add a fourth creature: a new frame, a fourth copy, and its own values. What do you change in the event sheet? Nothing The click event picks whichever copy is clicked and reads that copy's variables, so a new copy works straight away.
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 global variables).
Support: Give pairs the instance variable table filled in, so they can spend the time on the event.
Exit ticket
A game has 10 coins, each a copy of Coin with an instance variable value. The player touches one coin. The event adds Coin.value to Score. Whose value is added?
Only the touched coin's: the collision picked that copy, so Coin.value means its value.
What each step is for
whose name shows?: Predicting which name appears sets up the move: clicking an instance picks it, so the event reads that copy's instance variables.
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 it: the creature viewer: Building one sprite with three instances and one click event makes picking visible: the same event shows different stats for each creature.
one event, many creatures: The fade question and Nib's mistake test picking from the other side: an action in a picking event touches only the picked copy, not every instance.
a fourth creature: Adding a creature without touching the event sheet shows the payoff of instance variables and picking: the event already works for any copy.
your own character cards: A viewer of their own choosing uses the whole pattern (one object type, instance variables, a picking click event) in a new context.
Where it leads
Next: the challenge, a prototype of their own for a real user. In the games course, picking and instance variables come back with many enemies on screen.