Docs Tutorials
Your first Quick code
Write your first lines of code: a countdown, a score on screen, and two scripts that talk with send and on_message.
In the editor: Welcome ▸ Tutorials ▸ 3.2 ▸ ▶ Start goes on in your My Playground project with this lesson's checklist.
Build · about 35 minutes · Advanced mode
What you'll make: a race against the clock. Coins add to a score, and when the score is high enough, the level script hears about it and you win.
What you'll learn: where code goes, a level script, a variable, a timer, and send / on_message, the way one script tells another that something happened.
Before you start: do Scripts: events and actions. Switch the toolbar to Advanced (Basic | Advanced). Use any project with a small level. If its Models panel is empty (a Blank project), choose Create ▸ Add Starter Models first.
#1. A level script with a Code node
- Choose Edit ▸ Select None (Ctrl+Shift+A) so nothing is picked, then Create ▸ New Script…. The Scripts tab opens with a new script: an Event, an Action and an End node.
- Click its Event node and set it to Player enters the level.
- Click the Action node it came with and press Delete. Pick the Event node and click + Add node ▸ Add Code. The new node is wired in after it.
- In the Scripts panel at the bottom, right-click the script ▸ Run for the whole level. (A script with no object only runs once a level runs it.)
#2. A score and a timer
Type this into the Code node:
score = 0
hud_text("score", "Score: {score}", "top_right")
start_timer("Time", 60, "lose")
score is a variable: a name that holds a value. {score} in the text shows it and keeps it up to date. The timer counts down from 60 and the player loses at 0.
Press Check. It lists mistakes with their line numbers. Fix any, then press F5.
Play it now: the score shows top right and the clock counts down.
#3. Coins that send a message
- Place a Gem from the starter models with Place (2), then click it with Select (1) to pick it. Create ▸ New Script… makes a script that runs on it.
- Set its Event to Player touches / steps on it, replace the Action node with a Code node as before, and type:
score += 10
play("coin")
send("coin_taken", score)
self.remove()
- Go back to the level, pick the gem and copy it with Ctrl+D (the copy lands one tile over, script and all) until you have six. Drag them around the level with Select (1).
Play it now: each coin adds 10 to the score and disappears.
#4. Listen for the message
Go back to the level script's Code node and add these lines at the end:
on_message("coin_taken", function(total)
if total >= 50 then
local left = time_left("Time")
stop_timer("Time")
banner("Done with " .. left .. " seconds to spare!")
wait(2)
win()
end
end)
The coin doesn't know the level script exists. It only says "coin_taken". Anything listening hears it.
Play it now: pick up five coins before the clock runs out and you win.
#Try it yourself
- Make one gold coin worth 25 that sends a different message, and have the level script show a popup for it.
- Use an Event node set to A message is sent instead of
on_message, and compare the two. - Pick some nodes in a Level 2 script, right-click ▸ Copy as code, and paste them into a Code node.
#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.