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!
Control a LEGO Spike Robot with Motion: Using the Gyroscope

Control LEGO Spike Essential with Motion: Using a Gyroscope Introduce Today we are going to learn how to control a robot in a completely different way. Instead of pressing buttons or using a controller, we will use motion. The LEGO SPIKE hub has a built-in gyroscope that can detect how it is tilted, and we […]

Read More
Digestion Dash: The Ultimate Body Adventure!

Digestion Dash: The Ultimate Body Adventure! Get ready to race through the human body in Digestion Dash! In this game, you’ll follow food on an epic journey—from the first bite all the way to the end. Along the way, you’ll play mini-games and learn how your digestive system turns food into nutrients your body can […]

Read More
Build a LEGO Elevator!

Architecture Week Challenge: Build a LEGO Elevator! Can you design and build a working elevator using LEGO Robotics? This week at Sprattronics Learning Lab, your mission is to take your minifigures from low to high—just like real engineers do in skyscrapers around the world! Watch the Challenge Video First Before you start building, watch this […]

Read More
Can You Design a Video Game About Animal Senses?

Can You Design a Video Game About Animal Senses? Your Challenge Create a video game where the main character survives using its senses. You’ll need to: Your mission is to design a game that shows how animals sense, process information, and respond in order to survive. Why Animal Senses Make Great Video Games Animals experience […]

Read More
Interactive Weather Game

Interactive Weather Game: Learn the Water Cycle by Controlling a Cloud If you’re looking for a hands-on way to teach the water cycle and basic weather science, this browser-based game offers an engaging, intuitive experience. Players control a cloud, collect water vapor, release rain, and watch plants grow as they explore how water moves through […]

Read More
LEGO Baseplate Builder

Free 16x16 LEGO® Plate Builder: Create Custom LEGO Challenge Cards Unlock your creativity and kickstart your next building session with the Sprattronics LEGO Plate Builder. This free digital tool is designed specifically for educators, parents, and LEGO fans to design 16x16 LEGO Challenge Cards in seconds. Whether you are looking for a quick STEM warmup or a way […]

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