← Yop2D

How to keep the score after closing the game?

Beginner guide · no code

Français · English · Español · Deutsch · Italiano · Português · Русский · 中文 · 日本語 · العربية

ℹ️ For Yop2D Next, the new 2D + 3D version of Yop2D (coming soon). Button and node names are those of Yop2D Next.

🔍 How do I…? All short recipes, with a search

The score is written to a file each time a point is won, and read back at the start: it comes back even after closing the game.

You need:

Step 1: the score variable

  1. Left panel, Scene tab, GAME VARIABLES section: tap New variable. Name (no spaces): score; Type: Whole number; Starting value: 0. Then Apply.

Step 2: the text

  1. Tap Object → Texts → Text.
  2. Name it score_label and type 0 in its Text line.

Step 3: a button to try it

  1. Tap Object → Interactive → Button with text.
  2. Name it plus and type +1 in its Text line.

Step 4: the nodes

  1. Open the Blueprint.
  2. On Start → Load variables from a file: Variables (empty = all) score
  3. Loaded output → Modify Text (Object score_label, New text =score)
  4. On Object Click: Object plus → Add to Variable: Variable score, Value to add 1 → Modify Text (=score) → Save variables to a file: Variables (empty = all) score

The nodes

On Start
→
Load variables from a filescore
Loaded →
Modify Textscore_label · =score
On Object Clickplus
→
Add to Variablescore · 1
→
Modify Text=score
→
Save variables to a filescore

Try it

Tap Play, then +1 three times: the score is 3. Stop the game and play it again: it still shows 3.

👉 For a high score: make a second variable record and save only that one. The Save name setting lets you have several saves.