Prefabs
A prefab is the thing you will make most: a few parts that act as one object, with a script that says what it does. This page goes from nothing to complete working objects.
The game's own objects are prefabs too. They have their own page, Game prefabs, but everything here works on them as well.
What a prefab is
A prefab is parts plus an optional script:
- Parts are models, volumes and other prefabs, grouped under one object.
- The script is a class. It says what the object does when things happen to it.
You make a prefab when you want:
- something that does a job (a button, a pad, a secret);
- more than one of the same thing (ten skulls that all behave alike);
- a piece you can reuse in other maps.
Make one in the editor
We will make a skull you can shoot for points.
- In the World tab, drag a model into the map from the asset browser's Models. Pick any small one.
- From Volumes, drag a Hit volume over it. Scale it so it covers the model. It is a see-through red box; size is its scale (100 cm at scale 1).
- Select both and press Ctrl+G (Make prefab). They are now one object, grouped under an
Empty. Name it
Skull. - Each part keeps a part name inside the prefab. In the outliner they show as
Skull › ModelandSkull › Hit. Rename them if you like; scripts use these names.
Ctrl+Alt+G (Ungroup) takes a prefab apart again.
Save it to the library
With the prefab selected, click Save as new prefab. It now shows in the asset browser under My prefabs, and dropping it places an independent copy. Project → Prefab library deletes prefabs from the library.
Your first script
Select the prefab. In the Script box of the Game panel, click New. Keep the name Skull,
choose Basic prefab, and click OK. The editor makes scripts/prefabs/Skull.lua and opens it in the
Scripts tab. Replace what is there with:
local Skull = boz.Prefab:extend("Skull")
---@setting points int 100 "Points for shooting it"
function Skull:on_hit(player)
self:hide()
player:give_points(self.settings.points)
player:message("Skull found")
end
return Skull
Press Build & Run, shoot the skull, and it vanishes and pays you. Line by line:
local Skull = boz.Prefab:extend("Skull")
Makes a new class called Skull, based on boz.Prefab. Your class gets everything a prefab can
do, and adds to it.
---@setting points int 100 "Points for shooting it"
A setting. It shows in the editor's Settings box with the label Points for shooting it, as a whole number that starts at 100. Each skull you place can have its own value. Press Reload in the Script box after adding one.
function Skull:on_hit(player)
A hook: a function with a special name that runs when something happens. on_hit runs when
a Hit volume in this prefab is shot. player is who shot it.
self:hide()
self is this skull, the one that was shot. Hiding it makes it vanish, and its Hit volume stops
working too.
player:give_points(self.settings.points)
player:message("Skull found")
Pays the player the value from the editor, and shows a line of text on the screen.
return Skull
Hands your class to the game. Every object script must end with this. Without it the script does nothing and the log shows an error.
Choosing a template
New asks for a name and a template:
| Template | What you get |
|---|---|
| Empty | Just the class and return, for you to fill in |
| Basic prefab | A prefab with start, on_use and on_event, and a setting to show how it's done |
| Object | Extends one of the game's objects, which you pick from the Extends list, with that object's hooks ready |
The popup starts on what fits the selected object: Object with the right class for a door or a perk machine, and Basic prefab for your own prefabs. Empty extends the object's own class too, so a door stays a door. If a script with that name exists, the popup says so, and New attaches that script as it is.
The shape of a script
Every object script looks the same:
local Name = boz.Prefab:extend("Name") -- 1. make the class
---@setting ... -- 2. settings and links, if you want them
---@link ...
function Name:start() -- 3. hooks and your own functions
end
return Name -- 4. hand it back
boz is ready to use in object scripts. You don't need to require it.
Two things trip people up if Lua is new to them:
- Use a colon for methods:
function Skull:on_hit(player)andself:hide(). The colon is what passesself. selfis one object. If you place ten skulls, there are tenselfs, and each one has its own fields and settings.
A script's class extends another: it gets everything that class has, and any function you write with the same name replaces the original. Your own prefabs have nothing to lose, but a game prefab does, so there you hand the use back to the game. See Handing it back to the game.
You can add your own functions and call them from hooks:
local Skull = boz.Prefab:extend("Skull")
function Skull:collect(player)
self:hide()
player:give_points(100)
end
function Skull:on_hit(player)
self:collect(player)
end
return Skull
What every object has
Your class starts with all of this, before you write a line. self in a script, or anything from
boz.get, has the same things.
local Vault = boz.Prefab:extend("Vault")
function Vault:start()
log(self.name) -- "Vault_2": its name in the editor
log(self.kind) -- "prefab"
log(self:class_name()) -- "Vault"
log(self.settings.bonus) -- a value from the Settings box
log(self:position().x) -- where it is
local keypad = self:part("Keypad") -- one of its parts
log(keypad:part_name()) -- "Keypad"
log(keypad:parent().name) -- "Vault_2"
end
return Vault
Who it is
| You write | What you get |
|---|---|
self.name |
Its name in the editor. A part is "Prefab.Part". Copies each have their own. |
self.kind |
"model", "volume" or "prefab" (and "zone" or "sector" for those) |
self:class_name() |
The name of its class, like "Skull" or "Perk" |
self:is_a(boz.Door) |
True when it is that class, or extends it |
self:part_name() |
Its name inside its prefab, like "Door", or nil |
self:parent() |
The prefab it is part of, or nil |
Where it is
| You write | What you get |
|---|---|
self:position() |
{x, y, z} in centimetres, y up. For a prefab, the middle of its parts. |
self:rotation() |
{x, y, z, w}, a quaternion |
self:near(target, distance) |
True when within distance cm of a position or object |
self:exists() |
True while it is in the running level |
Its In the game box
Each switch in the editor can be read and changed.
| Switch | Read it | Change it |
|---|---|---|
| Visible | self:visible() |
self:show(), self:hide(), self:set_visible(on) |
| Walking | self:blocks_walking() |
self:set_blocks_walking(on) |
| Stops bullets | self:stops_bullets() |
self:set_stops_bullets(on) |
A hidden object reads false for the last two, because it stops nothing. A prefab reads true if any of its parts does. These two are only reliable on objects a script can reach: ones with a script, or ones a script names.
Its settings and links
| You write | What you get |
|---|---|
self.settings.name |
A value from the Settings box. Writing it changes it. |
pairs(self.settings) |
Every setting, to loop over |
self:links("name") |
The objects it links to, as a list |
self:linked_from("name") |
The objects that link to it, as a list |
"name" is your own ---@link, or one of the game's:
| Link | In the editor | On |
|---|---|---|
"power" |
Power switch | Anything that needs power |
"traps" |
Traps | Trap switches |
"siblings" |
Opens with | Doors and debris |
"spawns" |
Window spawns | Barricades |
local trap = boz.get("Lobby_Trap")
for _, switch in ipairs(trap:linked_from("traps")) do
log(switch.name .. " runs this trap")
end
Its parts
| You write | What you get |
|---|---|
self:part("Door") |
One part, as its class |
self:parts() |
A list of {name =, object =} |
Listening and sending
| You write | What it does |
|---|---|
self:on("hit", fn) |
Calls fn(object, ...) when the event happens to it |
self:send("name", data) |
The same as boz.send |
Volumes have their own values, and each game prefab adds its methods on Game prefabs. There's no way to move or turn an object from a script yet.
Hooks
These are the hooks a prefab has. You only write the ones you need.
| Hook | When it runs | Needs |
|---|---|---|
start() |
The level starts | Nothing |
on_use(player, volume) |
A player presses use | A Use volume |
usable(player, volume) |
Before a use costs anything: return false to refuse it | A Use volume |
on_hit(player, volume) |
Something is shot | A Hit volume |
on_enter(who, volume) |
Someone walks in | A Trigger volume |
on_exit(who, volume) |
Someone walks out | A Trigger volume |
on_event(name, data) |
A game event, or a boz.send |
Nothing |
volume is the part name of the volume, so one prefab can tell its volumes apart. A script
attached to a single volume, outside any prefab, gets no volume argument.
start
Runs when the level starts, once for each object. Use it to set the object up.
local Crate = boz.Prefab:extend("Crate")
function Crate:start()
self:hide() -- starts hidden, something shows it later
end
return Crate
start also runs when a saved game continues, after the object's saved fields are back. So a
good start looks at what is saved:
function Crate:start()
if self.collected then
self:hide()
end
end
on_use
Runs when a player stands at a Use volume and presses use. The volume's Prompt is the text they see, and its Cost is taken before the hook runs. If they can't pay, the hook doesn't run.
local Button = boz.Prefab:extend("Button")
function Button:on_use(player, volume)
player:message("Click")
boz.get("Front_Door"):open()
end
return Button
usable
Runs before a use takes the volume's Cost. Return false and a reason to refuse it: nothing
is paid, on_use doesn't run, and the prompt shows the reason instead of the cost. Use it for
anything that is sometimes not ready, so players never pay for nothing.
local Shrine = boz.Prefab:extend("Shrine")
function Shrine:usable(player, volume)
if self._used_this_round then
return false, "Come back next round"
end
return true
end
return Shrine
on_hit
Runs when a Hit volume is shot.
local Target = boz.Prefab:extend("Target")
function Target:on_hit(player, volume)
if volume == "Bullseye" then
player:give_points(500)
else
player:give_points(50)
end
end
return Target
on_enter and on_exit
Run when someone walks into or out of a Trigger volume. who depends on the volume's Set
off by:
- Players (the default):
whois the player. - Zombies:
whois a zombie, dogs and monkeys included. - Anyone:
whois either. Checkwho.zombiebefore you call player methods on it.
local Fence = boz.Prefab:extend("Fence")
function Fence:on_enter(who, volume)
if who.zombie then
who:kill()
return
end
who:message("Mind the fence")
end
function Fence:on_exit(who, volume)
log("someone left")
end
return Fence
A zombie that dies inside the volume counts as leaving, so on_exit runs for it too.
on_event
Runs for every game event (round_started, power_on, ...) and for every boz.send from your
own scripts. name says which it was. The full list is on the Events page.
local Lamp = boz.Prefab:extend("Lamp")
function Lamp:start()
self:hide()
end
function Lamp:on_event(name, data)
if name == "power_on" then
self:show()
end
end
return Lamp
Volumes
Volumes are how a prefab notices the world. They are invisible in the game. Drag one from Volumes in the asset browser, scale it, and make it a part of your prefab.
| Volume | Colour in the editor | Its event |
|---|---|---|
| Trigger | Teal | on_enter, on_exit |
| Hit | Red | on_hit |
| Use | Green | on_use |
Zone, Sector and Portal are volumes too, but they mark out the map instead of noticing things for a prefab: see Zones and Sectors.
Volume settings:
| Setting | What it does |
|---|---|
| Set off by | Triggers: Players, Zombies or Anyone |
| Only once | It works one time, then never again |
| Prompt | Use volumes: the text the player sees |
| Cost | Use volumes: the points it takes. No points, no hook. |
A hidden volume does nothing. So self:hide() on a prefab also switches off its volumes, and
self:part("Keypad"):hide() switches off just one.
Reading and changing a volume
A volume is a boz.Volume. It has everything in What every object has,
and every setting from the editor:
| You write | What you get |
|---|---|
volume:type() |
"trigger", "hit" or "use" |
volume:set_off_by() |
"players", "zombies" or "anyone" |
volume:once() |
True when Only once is on |
volume:used() |
True once it has fired |
volume:prompt(), volume:set_prompt(text) |
The Prompt |
volume:cost(), volume:set_cost(points) |
The Cost |
A new prompt shows the next time a player reaches the volume.
local Shrine = boz.Prefab:extend("Shrine")
function Shrine:on_use(player, volume)
local keypad = self:part(volume)
keypad:set_cost(keypad:cost() * 2) -- dearer each time
keypad:set_prompt("Pray again")
end
return Shrine
To put a script on a single volume outside any prefab, click New with the volume selected: it
extends boz.Volume, and self has these too.
Parts
A script can reach each part by its part name:
local Vault = boz.Prefab:extend("Vault")
function Vault:on_use(player)
self:part("Door"):hide() -- just the door
self:part("Frame"):set_stops_bullets(false)
end
return Vault
self:parts() lists them, each with its name and object:
function Vault:start()
for _, part in ipairs(self:parts()) do
log(part.name)
end
end
Prefabs can have prefabs inside them, and game prefabs can be parts too. self:part("Machine")
on a perk machine part gives you a real boz.Perk, with all its methods. From outside the prefab,
the same part is boz.get("Vault.Door").
What you do to the prefab itself goes to all of its parts: self:hide() hides all of them.
Settings
Settings let you change a value in the editor without touching the script, and give each placed copy its own value.
local Pad = boz.Prefab:extend("Pad")
---@setting bonus int 500 "Bonus points"
---@setting delay seconds 2 "Wait before paying"
---@setting once bool true "Pay only once"
---@setting greeting text "Welcome" "Message"
function Pad:on_use(player)
boz.after(self.settings.delay, function()
player:give_points(self.settings.bonus)
player:message(self.settings.greeting)
end)
end
return Pad
The shape is ---@setting name kind default "Label". After adding one, press Reload in the
Script box and it appears in the Settings box.
| Kind | In the editor | In the script |
|---|---|---|
int |
Whole number | Number |
float |
Number | Number |
bool |
Tick box | true or false |
seconds |
Seconds | Number of seconds |
text |
Text | String |
weapon |
A weapon of the map | Weapon name |
sound |
A sound | Sound name |
object |
An object of the map | Object name, for boz.get |
event |
An event name | String, for boz.send |
Read and change them through self.settings:
local value = self.settings.bonus
self.settings.bonus = value * 2
On a game prefab, the Settings box has the machine's own settings as well as
yours, and self.settings reaches both. self.settings.cost on a perk machine is its real cost.
Links
A setting holds a value. A link holds other objects, chosen in the editor with search and lines drawn in the viewport. Use a link when your script acts on something else in the map.
local Lever = boz.Prefab:extend("Lever")
---@link doors door many "Doors it opens"
function Lever:on_use(player)
for _, door in ipairs(self:links("doors")) do
door:open()
end
end
return Lever
The shape is ---@link name kind one|many "Label". Press Reload, and the Links box shows
your link. Click + to search, or select objects and use Link selected. × removes one.
self:links("name") always gives a list, even for one:
local target = self:links("target")[1]
The kind limits what can be linked:
| Kind | Links to |
|---|---|
perk |
Perk machines |
door |
Doors and debris |
barricade |
Window barricades |
trap |
Traps |
trap_switch |
Trap switches |
power_switch |
Power switches |
mystery_box |
Mystery boxes |
pack_a_punch |
Pack-a-Punch machines |
wall_buy |
Wall buys |
zombie_spawn |
Zombie spawns |
zone |
Zones (any of their boxes) |
sector |
Sectors |
teleporter |
Teleporters |
player_spawn |
Player spawns |
volume |
Volumes |
model |
Models |
prefab |
Your prefabs |
any |
Anything |
Links or a name? boz.get("Front_Door") is fine for one object in one map. A link is better
for a prefab you will reuse: each copy can point at something different, and renaming an object
doesn't break it.
Doing things
What every object has lists the calls. A few things to know:
An object only changes during play if a script can reach it. Objects with a script always can, and
so can any object a script names: boz.get("Name"), a prefab's parts, a setting that holds its
name, or a link to it. The build bakes everything else into the level, so big maps stay light.
A name built from pieces ("Light_" .. i) works as long as the first part is written out.
set_blocks_walking needs Walking: Blocks in the editor, because that is what reserves the
gap in the walkable area.
Moving and turning
Any object a script can reach can move. A prefab moves as one, with all its parts, and its collision and use prompts go with it.
local lift = boz.get("Lift")
lift:move_by({x = 0, y = 300, z = 0}, {seconds = 4, done = function()
log("at the top")
end})
boz.get("Statue"):turn_by(90, {seconds = 2})
| Call | What it does |
|---|---|
move_to(position or object, options) |
Moves it there. |
move_by({x, y, z}, options) |
Moves it by that much (centimetres; y is up). |
turn_to(degrees, options) |
Turns it to face that way (about the vertical axis). |
turn_by(degrees, options) |
Turns it by that much (positive turns left, seen from above). |
set_position(position), set_rotation(degrees) |
Puts it there at once. |
moving() |
True while it glides. |
stop() |
Stops a glide where it is. |
Options: seconds (glide over that time; without it, it jumps), rotation (turn while moving),
ride (players standing on it ride along; on by default), done(object) (called when it
arrives).
Players on a gliding object ride with it and can look around, then stand where it stops. The walkable area can't move: an object that blocks walking opens its gap once it leaves its start and closes it when it's back.
Timers
boz.after(5, function()
log("five seconds later")
end)
local beat = boz.every(1, function()
log("every second")
end)
beat:cancel() -- stops it
Times are in seconds of game time, so they stop while the game is paused.
Players
player in a hook is a boz.Player. Anywhere else, use boz.player():
local player = boz.player()
player:give_points(500)
player:give_perk("Juggernog")
player:give_weapon("mp40")
player:teleport(boz.get("Spawn_Room")) -- stands there, facing its way
if player:zone() == boz.get("Cellar") then player:message("Down here?") end
player:message("Hello", 5)
Talking between objects
Three ways, simplest first.
Call it. If you can reach the object, call its methods:
boz.get("Vault.Door"):hide()
Send an event. boz.send reaches every boz.on listener and every object's on_event. The
sender doesn't need to know who listens. Good for "something happened" messages.
-- in one script
boz.send("alarm", {room = "Lab"})
-- in another object's script
function Siren:on_event(name, data)
if name == "alarm" then
log("alarm in " .. data.room)
end
end
Listen from a map script. :on() watches an object from outside:
-- scripts/main.lua
local boz = require("boz")
boz.get("Vault"):on("use", function(vault, player, volume)
log("someone used the vault")
end)
Listeners at the top of main.lua work even though no level is loaded yet, and they keep working
across levels. They run after the object's own hook, and they can't stop it.
Saving state
Saved games keep two things for you:
- Fields on
self, unless the name starts with_. boz.saved, one table every script shares.
local Skull = boz.Prefab:extend("Skull")
function Skull:start()
if self.found then
self:hide()
end
end
function Skull:on_hit(player)
self.found = true -- this skull stays found in a saved game
self:hide()
boz.saved.skulls = (boz.saved.skulls or 0) + 1
end
return Skull
Use a _ name for anything that shouldn't survive a reload, like a "running" flag. Saved values
should be plain: numbers, strings, booleans, tables of those.
Recipes
Complete prefabs to copy. Each says what to build, then gives the script.
A secret wall
Shoot nothing, buy nothing: the player presses use on a wall and it opens.
Build: a wall model with Walking: Blocks and Stops bullets on, and a Use volume in front of it with the prompt Push the wall. Group them.
local SecretWall = boz.Prefab:extend("SecretWall")
function SecretWall:on_use(player)
self:hide()
player:message("The wall gives way")
end
return SecretWall
Hiding does all the work: the wall vanishes, people can walk through, bullets pass, and the Use volume stops prompting.
A pay-to-open gate
The game has this built in: Debris. It is any model that disappears when bought, and it can be extended.
Build: your gate model, and a Use volume with a Cost and the prompt Open the gate. Group them, attach this script.
local Gate = boz.Debris:extend("Gate")
function Gate:open(player)
if not boz.Debris.open(self, player) then
return false
end
player:message("The gate falls")
return true
end
return Gate
A three-skull easter egg
Shoot three skulls and a reward appears. It needs two scripts: one for the skulls, and one for whatever opens.
Build: the Skull prefab from earlier, placed three times. A hidden model or prefab called
Reward, with this second script attached.
-- scripts/prefabs/Skull.lua
local Skull = boz.Prefab:extend("Skull")
function Skull:start()
if self.found then
self:hide()
end
end
function Skull:on_hit(player)
self.found = true
self:hide()
boz.saved.skulls = (boz.saved.skulls or 0) + 1
if boz.saved.skulls == 3 then
boz.send("egg_done", {player = player})
end
end
return Skull
-- scripts/prefabs/Reward.lua
local Reward = boz.Prefab:extend("Reward")
function Reward:start()
if not boz.saved.egg_done then
self:hide()
end
end
function Reward:on_event(name, data)
if name == "egg_done" then
boz.saved.egg_done = true
self:show()
data.player:message("Something opened...")
end
end
return Reward
A timed trap
Pay to run it, and for a few seconds it kills every zombie close by.
Build: a model and a Use volume with a Cost and the prompt Run the trap. Group them.
local ZapPad = boz.Prefab:extend("ZapPad")
---@setting radius int 300 "Reach (cm)"
---@setting runs_for seconds 10 "Runs for"
function ZapPad:usable(player)
if self._running then
return false, "Running"
end
return true
end
function ZapPad:on_use(player)
self._running = true
local zap = boz.every(0.5, function()
for _, zombie in ipairs(boz.zombies()) do
if self:near(zombie, self.settings.radius) then
zombie:kill()
end
end
end)
boz.after(self.settings.runs_for, function()
zap:cancel()
self._running = false
end)
end
return ZapPad
_running starts with _ so a save never keeps it. While it runs, usable refuses uses before
the volume takes its cost, and the prompt says Running.
A teleporter
The editor has this built in: Teleporter. Drag it in, link its Destination, and for a stop in the wormhole drag a Wormhole and link Stop over at to it.
The same thing as a script of your own, to change any part of it. Give the Use volume a Cost;
usable refuses uses while it cools, so nobody pays for nothing.
local Pad = boz.Prefab:extend("Pad")
---@link target any one "Goes to"
---@link via any one "Stops at"
---@setting cooldown seconds 30 "Wait between uses"
function Pad:usable(player)
if self._cooling then
return false, "Cooling down"
end
return true
end
function Pad:on_use(player)
local target = self:links("target")[1]
if not target then
return
end
self._cooling = true
player:teleport(target, {via = self:links("via")[1]})
boz.after(self.settings.cooldown, function()
self._cooling = false
end)
end
return Pad
player:teleport stands the player on the target, facing the way it faces, with the game's
teleport flash. With via it stops there first and holds the player and their view still for seconds (2).
A moving platform
A floor that carries players up to a ledge and back, every ten seconds.
Build: a floor model with Walking: Walk on it, at the bottom. Group it into a prefab named
Platform with this script.
local Platform = boz.Prefab:extend("Platform")
function Platform:start()
local up = true
boz.every(10, function()
self:move_by({x = 0, y = up and 400 or -400, z = 0}, {seconds = 4})
up = not up
end)
end
return Platform
A lure
A button that pulls every zombie to a generator for 15 seconds, and counts the hits it takes.
Build: a Lure point volume named Bait next to the generator, with When they get there:
Attack it, and a prefab with a Use volume (Cost 1000, prompt Ring the bell).
local Bell = boz.Prefab:extend("Bell")
function Bell:start()
self.hits = 0
boz.get("Bait"):on("hit", function(lure, zombie)
self.hits = self.hits + 1
end)
end
function Bell:on_use(player)
boz.get("Bait"):start({seconds = 15})
player:message("They're coming for the generator")
end
return Bell
boz.lure(position or object, options) does the same anywhere without a Lure point. Only walking
zombies come, and they stop about 4.5 m away. See Lure points.
Winning the match
Ends the match with a win when the player reaches the exit.
Build: a Trigger volume named Exit (set off by Players), in a prefab with this script.
local Exit = boz.Prefab:extend("Exit")
function Exit:on_enter(who)
boz.end_match({win = true})
end
return Exit
The game shows its own game over and results; scripts hear match_ended with win = true, so
you can show your own message first.
When something goes wrong
Nothing happens at all. Open the editor's Log area or boz-log.txt in the client folder.
A script error shows there with its line, once, and it never crashes the game: the rest of your
scripts keep running. A call with a wrong argument (give_points("lots")) logs where it happened
and does nothing. Add log("here") to see
if a hook runs at all.
| What you see | Why | Fix |
|---|---|---|
| Log says the script must return a class | The last line is missing | End with return Name |
attempt to index a nil value (local 'self') |
A dot where a colon goes | function Skull:on_hit, self:hide() |
A game prefab stopped working, or the log names _handle or _piece |
The use wasn't handed back correctly | See Handing it back to the game |
on_hit never runs |
The prefab has no Hit volume, the volume is too small, or a model in front of it takes the shot | Add or resize it. Volumes in the tool settings bar helps. |
on_use never runs |
No Use volume, or the player can't afford its Cost | Check both |
hide() does nothing |
No script names the object, so the build baked it | Name it in a script (boz.get("Name")) |
| A new setting isn't in the panel | The panel wasn't reloaded | Press Reload in the Script box |
who:message errors in on_enter |
A zombie set it off | Check who.zombie first, or set Set off by to Players |
boz.get gives something that does nothing |
The name is wrong | Names are the ones in the outliner; parts are Prefab.Part |
The Problems panel checks the map before you build: Project → Check for problems.
Next: Game prefabs to change the game's own objects, or the Events table.
GitHub ↗