← Construct apps

A values journal

Build a journal app with three screens: pick a value you showed today, say what you did, then see every entry in a list. A global variable carries your choice from one screen to the next, an array keeps the entries, and a Repeat loop puts them in the list.

Almost every app has more than one screen: sign in, choose, confirm, see your list. Something has to remember what you did on the screen before.

Today's prototype has three screens. In Construct each screen is a layout, with its own event sheet.

  1. Choose: buttons for four values, such as Kindness, Courage, Curiosity and Teamwork (or your school's own values).
  2. Describe: "What did you do to show Courage?", a box to type in, and an Add to my journal button.
  3. Journal: a list of every entry so far, and a button to add another.

Three screens side by side: four value buttons; a question with a typing box and an Add button; and a list of entries such as "COURAGE: I asked a question in class".

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.

Does the choice survive?

On screen 1 you click Courage. Its event sets the global variable Chosen to "Courage", then goes to screen 2. Screen 2's On start of layout sets its question to "What did you do to show " & Chosen & "?". What does the question say?

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

Try the finished app

This is the finished app you'll build. Each screen shows its own event sheet.

Try it yourselfYour edits are saved in this browser.

Add two entries with different values. Watch Chosen and Journal.Width under the event sheet.

Use the board. This ticks when you get there.

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

Build it: three screens

Screen 1: choose

  1. Start a New project called Values journal.
  2. On Layout 1, insert a title Text, Values journal, and a line below it, Which value did you show today?
  3. Insert four Buttons, one per value, named KindnessButton, CourageButton and so on, with the value as each one's text.
  4. Insert an Array object (it has no picture on the screen). In its Properties set Width to 0, Height 1, Depth 1, name it Journal, and make sure Global is ticked, so it carries on to the other screens.

Screen 2: describe

  1. In the Project panel, right-click Layouts and add a layout. If Construct offers to make an event sheet for it, say yes.
  2. On Layout 2, insert a Text called Question, a Text Input (make it wide), and a Button called AddButton with the text Add to my journal.

Screen 3: the journal

  1. Add Layout 3 the same way. Insert a title Text, My values in action, a List object (make it tall), and a Button called AnotherButton with the text Add another.

Each layout must use its own event sheet: click an empty part of the layout and check its Event sheet property. If a screen's events never seem to run, this is the first thing to check.

Events

  1. In Event sheet 1, add a global variable Chosen, type String (text), starting empty.
  2. Still in Event sheet 1: KindnessButton, On clicked → System, Set value, Chosen to "Kindness", then System, Go to layout, Layout 2. Do the same for each value button.
  3. In Event sheet 2: System, On start of layout → Question, Set text: "What did you do to show " & Chosen & "?"
  4. Also in Event sheet 2: AddButton, On clicked → Journal, Push, back, X axis, value uppercase(Chosen) & ": " & TextInput.Text, then Go to layout, Layout 3.
  5. In Event sheet 3: System, On start of layout → List, Clear.
  6. Add a separate event in Event sheet 3: System, On start of layout, then right-click it, Add another condition, System, Repeat, Journal.Width times. Action: List, Add item, Journal.At(loopindex).
  7. AnotherButton, On clicked → Go to layout, Layout 1.
  8. Preview from Layout 1 and add three entries.

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

Lists and loops

The journal has 3 entries, so Journal.Width is 3. The Repeat runs 3 times. What is loopindex each time?

Nib's journal only ever shows the latest entry. Click the line where Nib first goes wrong.

What if Chosen were an instance variable on a button in screen 1, not a global variable?

ModifyChange the problem on purpose and see what happens.

Count the entries

Add a Text to Layout 3 and set it in the first On start of layout event: "You've added " & Journal.Width & " moments"

Screen 3 should say "You've added 5 moments". Which expression gives the 5?

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

Test the flow

Ask someone to add two entries without any help from you. Watch where they pause or click the wrong thing. Then change one thing: a clearer button name, a Back button on screen 2, or an empty-box check before saving.

Now you can
Next lesson5. Creature statsBuild 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.
For teachers

Students build a three-screen journal: choose a value, describe what they did, and see every entry in a list. A global variable (Chosen) carries the choice between layouts, an Array (Journal) stores entries with Push, and screen 3 rebuilds a List from the array with Repeat and loopindex in a separate event from Clear. About 75 minutes.

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

Students will be able to

Before class

The values are examples. Use your school's own values if it has them, or let students choose four that matter to them. Entries are personal: students keep the app on their own device and nothing is collected or shared. Keep any class discussion on made-up entries.

Check before class: the Array's Global property. If the array isn't kept between layouts, entries pushed on screen 2 won't be there on screen 3. Step 4 tells students to make sure Global is ticked; confirm the property name in the current editor.

When a layout is added, Construct usually offers to add an event sheet too. If a student has extra or missing sheets, click an empty part of each layout and set its Event sheet property.

Step 12 and 13 must be two separate events. If Clear sits in the same event as the Repeat, it runs on every repeat and only the last entry is left (the Investigate bug).

The journal forgets everything when the preview closes. That's fine for a prototype; saving between sessions (Local Storage) is a stretch.

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.

Running the lesson

  1. Predict: ask what 'global' might mean before the reveal.
  2. Build it: checkpoint after step 10: does screen 2 show the chosen value? Fix that before arrays.
  3. Investigate: write loopindex 0, 1, 2 under three entries on the board, and point to At(0), At(1), At(2).
  4. Make: pair students from different tables, so the tester hasn't seen the app built.

The hard part (on purpose)

This is the longest build in the course, and the most common failure is a layout using the wrong event sheet, so nothing on that screen happens. Check each layout's Event sheet property before anyone debugs further.

When students get stuck

Stretch and support

Stretch: Save the journal between sessions with the Local Storage object (Array AsJSON and Load), or show the newest entry first.

Support: Build screens 1 and 2 as a class first, then let students build screen 3 in pairs.

Where it leads

Next: Creature stats, where one object has many copies, each with its own values.

What each step is for