February 25, 2026

Code a Mini Economy Town in Scratch

Development Guide: Code a Mini Economy Town in Scratch

This guide explains how to build a dice-powered city simulator in Scratch. You will learn how to manage a virtual economy, use cloning to build a visual city, and create a multi-level progression system.

You can check out this project on Scratch. Dicy City Scratch

We made a more polished version here. Check out the YouTube video below.


Step 1: The Economy Engine

The Goal: Create a dice-rolling mechanic that generates money.

  • Setup Variables: Create variables for Coins, Dice Total, and Roll Count.
  • The Dice Sprite:
    • Give your Dice sprite 6 costumes (one for each side).
    • When the sprite is clicked, use the pick random 1 to 6 block to set the Dice Total.
    • Switch the costume to match the number.
  • The Payout System:
    • Use a Broadcast called Check Payout.
    • When the dice stops rolling, send the broadcast. Every building you own will "listen" for this and check if the Dice Total matches its specific winning number to give you Coins.

Step 2: Visual City Building (Cloning)

The Goal: Make buildings appear on the screen when you buy them.

  • The Building Sprite:
    • Create one sprite for every building (Wheat Field, Cafe, Mine, etc.).
  • The Buying Logic:
    • Create "Buy" code for each building. When clicked, check: if Coins > Cost.
    • If successful, subtract the cost from Coins and Create a Clone.
  • Cloning the Building:
    • Now update the code for When I Start as a Clone.
    • Inside that block, update the Payout to the value of what happens when the dice rolls that number.
    • Add a script: when I start as a clone, use go to x: (random) y: (random) to place the building in your city area.
  • Check Payout
    • When I receive Check Payout, check to see if the Dice Roll equals the activation number.
    • Update the number of coins by the payout value.

Step 3: Strategic Synergies (Math Operators)

The Goal: Create advanced buildings that give bonuses based on other buildings you own.

  • Tracking Collections: Create variables to track totals, such as Total Flower Gardens or Total Mines. Every time you buy one, change that variable by 1.
  • The Synergy Logic:
    • For a building like the Flower Shop (which pays out based on how many gardens you have), use the Operator blocks.
    • When the dice hits the Flower Shop’s number, use: change Coins by (Total Flower Gardens * 3).
    • This rewards the player for planning their city layout instead of just buying random items.

Step 4: Level Progression & Resets

The Goal: Create a sense of achievement by unlocking new items and clearing the board for a new challenge.

  • The Level Variable: Create a variable called Level.
  • Unlocking Content:
    • On your "Buy" buttons, use an if block: if Level > 2 then show else hide.
    • This keeps the screen clean and introduces new buildings (like the Mine or Restaurant) only when the player is ready.
  • The Level-Up Script:
    • Create a script that constantly checks: wait until Coins > Goal.
    • When the goal is hit, show a "Level Up!" message.
    • The Reset: To start the new level, set Coins to 5, set Roll Count to 0, and use broadcast Clear City.
    • All building clones should have a script: when I receive Clear City, delete this clone.

Step 5: Adding Visual "Juice"

The Goal: Use motion to show the player exactly when and where they are earning money.

  • Flying Coins:
    • Create a small "Coin" sprite.
    • When a building clone triggers a payout, it should create clone of Coin.
  • The Animation Script:
    • Inside the Coin clone: when I start as a clone.
    • go to [Building Sprite] (the one that just paid out).
    • show.
    • glide 0.5 secs to [Coin Counter Display].
    • delete this clone.
  • Unlocking the Second Die:
    • At Level 3, show a new button: "Roll 2 Dice."
    • When clicked, change the math to: set Dice Total to ((pick random 1 to 6) + (pick random 1 to 6)). This allows the player to finally hit high-number buildings like the Mine (11 or 12).

Summary of Logic

By the end of this project, you have mastered:

  1. Events: Using broadcasts to coordinate between the dice, the shop, and the city.
  2. Cloning: Managing dozens of visual objects without creating dozens of separate sprites.
  3. Conditionals: Checking if a player has enough money or has reached the correct level to proceed.
  4. Math Operators: Creating complex economic bonuses that make the game strategic.

Sprattronics Learning Lab

Maximize your education!
Code a Mini Economy Town in Scratch

Development Guide: Code a Mini Economy Town in Scratch This guide explains how to build a dice-powered city simulator in Scratch. You will learn how to manage a virtual economy, use cloning to build a visual city, and create a multi-level progression system. You can check out this project on Scratch. Dicy City Scratch We […]

Read More
Code a Town Economy Game

Code a Mini Economy Town: A Development Guide This guide breaks down the creation of Dice City Tycoon, a browser-based economic simulator. We developed this game in five distinct phases, moving from a simple text-based engine to a polished, multi-level city builder. This page is all about building the game in HTML for a Web Browser. […]

Read More
Create a Downhill Skier Game

DOWNHILL SKIER GAME CODING CHALLENGE The Challenge Your mission is to create a downhill skiing game.The skier stays near the top of the screen while the world moves toward them. Goal:Avoid obstacles for as long as possible. This game uses a classic trick in game design:If the environment moves, it feels like the player is […]

Read More
Sarah E. Goode LEGO Folding Desk to Bed Build

Overview Design a LEGO build that transforms from a desk into a bed, inspired by Sarah E. Goode’s folding cabinet bed. This challenge highlights how engineers solve real problems—like limited living space—by creating furniture that serves multiple purposes. Watch the full build video: https://youtu.be/h9pIRXLIa8w Best for: Grades 2–6Kits: LEGO Spike Prime or Spike EssentialTime: 45–60 […]

Read More
Alexander Miles - LEGO Spike Automatic Door Build

Overview Build a LEGO robot that opens and closes a door automatically—no hands required. This challenge is inspired by Alexander Miles, the inventor whose automatic elevator door system made buildings safer and helped shape modern cities. Watch the full build video: https://youtu.be/CT-ELr0o-v0 Best for: Grades 2–6Kits: LEGO Spike Prime or Spike EssentialTime: 45–60 minutes Who […]

Read More
Garrett Morgan LEGO Traffic Signal Build

Build a working LEGO traffic signal inspired by Garrett Morgan, the inventor whose improved traffic light design helped make roads safer. In this challenge, students design a motorized signal system, learn why timing and clear communication matter, and connect history to real engineering decisions. Watch the Video! Click Here Who Was Garrett Morgan? Garrett Morgan […]

Read More
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram