← Construct apps

Creature stats

Build a character viewer: click a creature and see its stats as text and bars. All three creatures are copies of one sprite, each with its own instance variables, and clicking one picks just that copy, so the event reads the stats of the one you clicked.

Character select screens, product pages and contact lists all work the same way: one design, many copies, each with its own details.

Today's prototype shows three made-up creatures: an Emberfox, a Tidecrab and a Mossbear. Click one, and its name, stats and special ability appear below.

You could make three separate sprites, each with its own events. Instead you'll make one sprite with three copies. In Construct the sprite is an object type, and each copy is an instance. Instance variables belong to the object type, but each instance keeps its own values: the Emberfox's power and the Tidecrab's power are different numbers.

The creature viewer: three creatures in a row, and below them the Tidecrab's name, its power, speed and defence as bars, and its special ability.

How this lesson works: Predict, Try, Investigate, Modify, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

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?

TryTry it on the board and compare the result with your prediction.

Try the finished app

This is the finished app you'll build. Click the Tidecrab last.

Try it yourselfYour edits are saved in this browser.

Click each creature in turn. One event shows all three.

Use the board. This ticks when you get there.

TryTry it on the board and compare the result with your prediction.

Build it: the creature viewer

One sprite, three looks

  1. Start a New project called Creature stats.
  2. Insert a Sprite called Creature. Draw the first creature (a simple shape and colour is fine).
  3. In the animation editor's Animation frames panel, right-click and add a frame. Draw the second creature. Add a third frame for the third.
  4. Close the editor. In the sprite's animation properties, set Speed to 0, so it doesn't flick between frames.
  5. Copy and paste the sprite twice, so there are three in a row. Select the second and set its Initial frame to 1; the third to 2.

Instance variables

  1. Select any Creature. In Properties, find Instance variables and add: name (String), power, speed, defence (Numbers, 0 to 100), and ability (String).
  2. Click each creature in turn and fill in its own values. Make up the numbers, but be ready to say why each creature has them.

The stats area

  1. Below the creatures, insert Text objects: NameText, PowerText, SpeedText, DefenceText and AbilityText. Leave their text empty.
  2. Beside PowerText, insert a Sprite called PowerBar: a red rectangle 200 wide. Set its width to 0 for now. Make SpeedBar and DefenceBar the same way in other colours.

Make the sprites clickable

  1. Insert the Mouse object (and Touch, if your class uses tablets). It has no picture; it lets events react to clicks on any object.
  2. Add the event: Mouse, On object clicked, left button, clicked, Creature.
  3. Add actions: NameText, Set text, Creature.name; PowerText, Set text, "Power: " & Creature.power; and the same for speed and defence; AbilityText, "Special: " & Creature.ability.
  4. Add PowerBar, Set width, Creature.power / 100 * 200, and the same for the other two bars.
  5. Preview and click each creature.

InvestigateWork out why it happens, one step at a time.

One event, many creatures

You add one more action to the click event: Creature, set opacity to 40 (faded). You click the Mossbear. Which creatures fade?

Nib wanted the other two creatures to fade. Click the line where Nib's thinking goes wrong.

Why use instance variables here, not global variables?

ModifyChange the problem on purpose and see what happens.

A fourth creature

Add a fourth frame in the animation editor, paste a fourth copy of the sprite, set its Initial frame to 3, and fill in its instance variables. Then preview and click it.

You add a fourth creature: a new frame, a fourth copy, and its own values. What do you change in the event sheet?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Your own character cards

Choose your own set: made-up creatures, pets, robots, plants or anything with at least three characters. 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.

Now you can
Next lesson6. Challenge: your own appPlan, build and test a prototype of an app for a real person. Choose a problem, sketch the screens and how they connect, decide which variables and events it needs, build it in milestones, then watch someone use it and improve one thing.
For teachers

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. About 75 minutes.

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

Students will be able to

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.

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

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.

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.

What each step is for