ℹ️ 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
A variable is a box with a name that keeps a number or a text during the game: the score, the lives, the money, the player's name.
You need:
- a project open in Yop2D Next.
Step 1: create the variable
- In the RESOURCES panel, GAME VARIABLES part, tap New variable.
- Name (no spaces): for example score. The name starts with a letter, with no space or sign.
- Type: Whole number (score, lives), Decimal number (speed, time), Text (a name), Yes / No (a door open or closed), Inventory list (the objects picked up).
- Starting value: for example 0 for the score, 3 for the lives. Then Apply.
👉 You can also create the variable while setting a node: New variable…, at the bottom of the list of variables.
Step 2: change it
- Add to Variable: adds a number (1 to the score) or takes one away (−1 to the lives).
- Modify Variable: sets an exact value (lives = 3 at the start of a level).
Step 3: show it
Place a text object, then use Modify Text with =score. The = sign is required: without it, the text shows the word “score”.
Step 4: test it
- If a variable…: for example, if vies (lives) is lower than or equal to 0 → game over.
- When Variable Changes: an event that fires as soon as the variable changes.
The nodes
Example: the hero picks up a coin, the score goes up by 1 and is shown.
If object touches TagHero · piece
→
Add to Variablescore · 1
→
Modify TextScoreText · =score
Try it
Tap Play and pick up coins: the number goes up.
👉 “Restart the scene” does not set the variables back to their starting value: add “Modify Variable” just before it (see My game doesn't work).