Docs Tutorials
Take apart: Code World
Walk through a lab where every machine runs on code, read the scripts behind them, and change one.
In the editor: Welcome ▸ Tutorials ▸ 3.3 ▸ ▶ Start opens a fresh copy of Code World with this lesson's checklist.
Take apart · about 40 minutes · Advanced mode
What you'll learn: how a whole game shares code through a library, how three objects talk with messages, and how an object remembers things with its own values.
Before you start: do Your first Quick code.
#1. Play it first
Make a new project from the Code World sample (File ▸ New Project…) and press F5. It's a glowing lab in four levels: Code World, the Tinker Workshop, the Deep Lab and the New Lab. Each station gives a Code Gem when you solve it, and its sign names the script to read. Solve three stations, including the Plate Vault (on the west side of Code World, the level you start in) and the Click Counter (through a portal, in the Tinker Workshop).
#2. The library every station shares
Stop with Shift+F5. Switch to Advanced (the Mode: Basic button on the toolbar), then in the Scripts tab open Lab. It's a library: its code makes a table called Lab with a function Lab.award, which gives the gem, updates the gem counter and calls win() when you have all 31.
Any script borrows it with require("Lab"). Open Vault gem and find the line that does.
#3. Three plates and a door
The Plate Vault never wires its plates to its door. Open these two scripts side by side:
- Pressure plate is on all three plates. When touched, it runs
send("plate", self.color_name). - Vault door has
on_message("plate", ...). It keeps a list of the colors so far and opens when they matchblue, red, green.
Click a plate in the level with Select (1) and look at Properties ▸ Values for code. Its color_name is set there, so one script works for all three plates.
#4. A button that remembers
Open Click Counter. self.count is a value stored on the button itself. (self.count or 0) + 1 starts it at 0 the first time.
#5. Change it
- In Vault door, change the secret order to
red, green, blue. Change the sign by the vault (Plate Vault, messages) so players can still solve it. - In Click Counter, change the 5 presses to 10 in three places:
self.count == 5,self.count < 5and5 - self.count. - Press Check in each script before you play.
Play it now: the vault opens to the new order, and the counter wants 10 presses.
#Try it yourself
- Add a fourth plate with its own
color_nameand make the order four colors long. - Open Travel terminal and find how
choice()builds its menu of stations.
#Learn more
#Next
Get an email when Voxel Game Maker launches
It's coming to Steam with a launch discount. One email on launch day, the odd progress update, nothing else.