← Yop2D

How do I make a product list (data table)?

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

For a shop, an inventory or a simulation game: instead of creating one variable per product, write all your products in a data table: one row per product, one column per piece of information (price, image, stock). The game then builds one card per product.

You need:

Step 1: the table

  1. Tap Object → Tools → Data tables, then Open.
  2. Tap + New table and name it Products.
  3. Tap + Add a row for each product: Apple, Bread, Milk. The first column, Name, holds the product's name.
  4. Tap + (at the end of the columns) to add Price, Image and Stock.
  5. Tap the name of the Image column and choose Kind: image. Price and Stock stay as number.
  6. Tap each cell to fill it (Price 2, 3, 1.5; one image per product; Stock 10, 5, 8). Then Done.

Step 2: the models

  1. Put an object in the scene (an image or a Square) and name it Card. In the Inspector, line Tag (family of objects), type produit.
  2. Tap Object → Texts → Text and name it Price.
  3. Place these two objects off the screen: they are the models, the game makes one copy per product.

Step 3: one card per product

  1. Open the Blueprint.
  2. On Start → For each table row: Data table Products.
  3. Output For each one → Create object: Object Card, X position =numero_ligne * 300, Y position 300.
  4. → Give a row's values (table): Object the involved object (the card just created), Data table Products, Row =ligne_tableau.
  5. Output Found → Create object: Object Price, X position =numero_ligne * 300, Y position 450.
  6. → Modify Text: Object the involved object, New text =tableau("Products", ligne_tableau, "Price").

For each table row goes through each product, one after the other: the variable ligne_tableau holds its name (Apple, then Bread, then Milk) and numero_ligne its number (1, 2, 3). Give a row's values (table) copies the row into the card: each column becomes a variable of the card (Price → price, Stock → stock) and the image column changes its image.

Step 4: change the stock

The table keeps the starting values. During the game, you change the card's stock variable:

  1. On Object Click: Object # produit → Add to Variable: Object the involved object, Value to add -1.
  2. Line Variable: tap New variable… and create stock (Whole number). Because the node targets the card, it is the tapped card's stock that goes down.

Read a value in a formula

Anywhere you write a formula: =tableau("Products", "Apple", "Price") gives 2 (the table, the row, then the column). For example Modify Text of a text, New text =tableau("Products", "Apple", "Price").

The nodes

On Start
→
For each table rowProducts
For each one →
Create objectCard · X =numero_ligne * 300 · Y 300
→
Give a row's values (table)the involved object · Products · =ligne_tableau
Found →
Create objectPrice · X =numero_ligne * 300 · Y 450
→
Modify Textthe involved object · =tableau("Products", ligne_tableau, "Price")
On Object Click# produit
→
Add to Variablethe involved object · stock · -1

Try it

Tap Play: three cards appear, each with its image and price. Add a Banana row to the table: a 4th card appears, without touching the nodes.

👉 Cards placed by hand? Name them Apple, Bread, Milk and leave Row empty: each card takes the row with its name. The Monster table template (Templates tab) works this way.