← Teacher guide

Creature stats

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.

Construct apps · One object · about 75 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

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

  1. Predict: ask how Construct could know which creature you mean.
  2. Build it: check at step 7 that every creature has its own values before anyone builds the stats area.
  3. Investigate: act it out: three students are creatures, one clicks; only the clicked one obeys the next instruction.
  4. 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.

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 seeA question to askThe 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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

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.