Voxel Game Maker

Docs Tutorials

Debugging

Plant a bug, then find it with watch, breakpoints, Live Values, log points and the problems list.

In the editor: Welcome ▸ Tutorials ▸ 5.2 links here; tick Done in the lesson list when you've finished.

Reading lesson · about 30 minutes · Advanced mode

What you'll make: a shrine with a bug in it, and the tools to find bugs like it fast.

What you'll learn: watch(), breakpoints and stepping, Live Values, log points, and the problems list.

Before you start: do Performance.

#1. Plant a bug

  1. Place three Coin pickups (as in A coin hunt) and any model as a shrine.
  2. Pick the shrine and choose Create ▸ New Script…. Set its Event to Player presses E (the use key) and replace the Action node with a Code node (+ Add node ▸ Add Code):
local coins = has("Coin")
watch("coins", coins)
if coins > 3 then
  take("Coin", 3)
  heal(50)
  popup("The shrine glows.")
else
  popup("Bring 3 coins.")
end

Press Check. It finds nothing: Check catches code that can't run, not code that does the wrong thing.

Play it now: collect all three coins and press E at the shrine. It still says "Bring 3 coins."

#2. Watch the value

Play again, collect the coins, press E at the shrine and press F3. watch() shows coins in the debug panel and in the Output panel's Watch line. It says 3, so the count is right. The bug is in what the code does with it.

#3. Stop on the line

  1. Click left of the if line's number in the Code node. A red dot shows: a breakpoint.
  2. Choose Play ▸ Play Here (in the Editor), so the game runs inside the editor. Press F5, collect the coins and press E.

The game pauses before that line and shows the code's local values. Press F10 to step one line at a time. It jumps to else, because 3 is not more than 3. Press F5 to carry on and Shift+F5 to stop. Change > to >= and click the dot again to take it off.

Play it now: the shrine glows.

#4. Change values while it runs

Press F5 and open Play ▸ Live Values… while the game plays in the editor. It shows the game's variables, switches, counters and items as they change. Click the number of coins and type 3 to test the shrine without collecting anything.

#5. Print without adding print

Right-click a line in the Code node ▸ Log point on this line… and type coins is {coins}. Each time that line runs, Output prints the message and the game carries on. Exported games ignore breakpoints and log points, so you can leave them in.

#6. Read the problems list

  • Every save lists logic problems in Output: a switch checked that nothing sets, an item taken that nothing gives, nodes nothing reaches. Tools ▸ Logic Problems… lists them on demand.
  • Play ▸ Check My Game… finds missing sounds, levels and scripts, and places the player can't walk to.
  • In Output, pick Game logic in the list next to Clear: while you play in the editor, it lists every Trigger that ran or was skipped, and why.

#Try it yourself

  • Open the Logic Lab sample (File ▸ Open Sample Project), read sign 17, and in the Scripts tab open Counter bot. Set a breakpoint on its Condition node by clicking the dot on its title.
  • Run Check My Game… on your Level 4 capstone and fix everything it finds.

#Learn more

#Next

Polish and feel.