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!
Arctic Animal Science: Polar Bears

1. Introduction and Build Meet an Apex Predator Polar bears are the largest land predators on Earth. They live in the Arctic and the Northern Hemisphere, where they spend much of their time on sea ice and in the surrounding coastal areas. Polar bears are apex predators, which means they are at the top of […]

Read More
Arctic Animal Science: Reindeer Adaptations

1. Introduction & Build Welcome to the Arctic Tundra! The Arctic tundra is a challenging place to live. Temperatures can become extremely cold, snow can cover the ground, and finding food can become difficult. Yet reindeer survive here year after year. How do they do it? Reindeer have special adaptations that help them survive in […]

Read More
Arctic Animal Science : Walruses

Welcome to the Arctic Ocean! The Arctic Ocean is the smallest and shallowest of Earth's five oceans. It surrounds the North Pole and is one of the coldest ocean environments on Earth. Much of the Arctic Ocean is covered by sea ice, especially during the coldest parts of the year. Even though the environment is […]

Read More
Arctic Animals: Engineering in a Frozen World

Welcome to the Arctic! The Arctic is the far northern region of Earth. It surrounds the North Pole and includes everything north of the Arctic Circle, an imaginary line located at about 66.5° north latitude. The Arctic is one of the coldest places on Earth. Much of the land is treeless, and the region is […]

Read More
Get the Gold

Get the Gold! LEGO® Education Computer Science & AI Grade 3 - 5 Unit 1 • Lesson 1 Student Sheet Mission A treasure of gold is waiting! Your job is to build a horse and carriage, then write a program that helps your robot travel from the castle to the gold and safely back home […]

Read More
LEGO Education Computer Science & AI Kit: The Ultimate Getting Started Guide

LEGO Education Computer Science & AI Kit: The Ultimate Getting Started Guide You Placed Your Order and the Kit is on the Way... Now What? Congratulations! You've ordered the LEGO Education Computer Science & AI Set. Whether you're a classroom teacher, homeschool parent, after-school educator, or robotics enthusiast, you're about to unlock dozens of engaging […]

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