Voxel Game Maker

Docs Tutorials

Take apart: The Gilded Mug

Run a tavern for an evening, then see how customers, stations and one world script make a management game.

In the editor: Welcome ▸ Tutorials ▸ 4.4 ▸ ▶ Start opens a fresh copy of The Gilded Mug with this lesson's checklist.

Take apart · about 40 minutes · Advanced mode

What you'll learn: how a management game is put together: customers who arrive and wait, stations that make things, money and reputation, and an end-of-day shop, all driven by one world script.

Before you start: do Take apart: Midnight Prowler.

#1. Play it first

Open The Gilded Mug from the sample games on the welcome window's Start tab (or File ▸ New Project… and pick it) and press F5. After Mags's welcome, customers walk in, sit and order. Press E at a station to pick up the dish, then E on the customer to serve it before their patience bar runs out. Play until the evening's ledger and buy an upgrade.

#2. Read the notes

Stop with Shift+F5 and switch to Advanced with Basic | Advanced on the toolbar, so the Explorer, the Scripts tab and the Prefabs tab show. Open Explorer ▸ Notes. The project note tells you where to look first: the world script The Gilded Mug, then the Station and Customer scripts.

#3. A station is a named object

Click the ale taps. It's a plain model. Two things make it a station: its Script name is Taps, and it has a Script behavior running Station. The Pot, Kettle, Oven and Bucket share the same script. Station reads the object's name to know what it makes and how long it takes:

local makes = {Taps = "Ale", Pot = "Stew", Kettle = "Tea", Oven = "Pie"}
local takes = {Taps = 0.5, Pot = 0.8, Kettle = 3, Oven = 4}

#4. A customer is a prefab

Customers aren't placed in the level; the world script spawns them from prefabs. To look inside one, open the Prefabs tab, click Farmer (one of six customer types) and click an empty spot on the tavern floor to place a copy. Press 1 (Select) and click the copy. Properties shows it's a copy of the Farmer prefab, and its behaviors:

  • a Daily routine with no hours, so it walks wherever the world script sends it: in from the street to a free stool;
  • a Script behavior running Customer, with its Prompt set to Serve;
  • an Attached HUD, the order bubble, which starts hidden. Code shows it and fills its Patience bar, which turns red under 30%.

Keep the copy for step 6, then delete it.

#5. One script runs the evening

Open The Gilded Mug in the Scripts tab. Mags's welcome is three Say nodes, then one Code node runs the evening. This is the pattern of a management game, a loop that never waits for you:

  1. A customer arrives when a stool is free.
  2. Every quarter second, each customer's patience runs down.
  3. Serve in time and they pay the price plus a tip for speed. Run out and they leave, and your reputation drops.
  4. At midnight the doors close, the ledger shows the day, and you spend coins on upgrades.

Near the top are the numbers to tune: local DAY = 150 (seconds the doors are open), local DAYS = 5 and local PRICE = {Ale = 4, Stew = 6, Tea = 5, Pie = 9}. The game is won with five stars by the end of day 5.

#6. Change it

  1. Raise the Pie's price in PRICE.
  2. In Station, make the Kettle faster in takes. Tea is on the menu only after you buy the kettle in the evening's shop.
  3. On the Farmer copy's Script behavior, change the Prompt to Take order and click Apply to all in its Prefab card, so every Farmer gets it. Then press Delete to remove the copy (the prefab keeps the change).
  4. In Game Settings ▸ Physics, raise Walk speed and see how much easier a busy evening gets.

Play it now: play an evening and check the ledger's total.

#Try it yourself

  • Patience is set in the world script when a customer arrives. Find it and make customers more patient on day 1.
  • Change the upgrade prices in the world script's shop.
  • Repaint the Farmer's clothes in the Model tab and watch him walk in.

#Learn more

#Next

Make a genre's core loop.