Game data
game describes this room’s game version. rooms.create inherits the server’s version. A world imported from a vanilla folder carries its own.
game.versiongame.world_heightgame.entities.names { mob = true }Blocks
game.block(name) returns one block in this version’s numbers, or nil
if this game lacks it. behaviour is the rule Citadel runs for the block
("grass", "flowing", "torch", "falling"), or nil for an inert
block.
local stone = game.block("stone")print(stone.hardness)print(stone.behaviour)print(game.block("grass_block").behaviour)print(game.block("water").random_ticks)print(game.block("torch").light)print(game.block("glass").light_filter)print(game.block("obsidian").resistance)print(game.block("oak_planks").flammability)print(game.block("water").material.liquid)resistance, flammability and material are nil, not zero, in a game
with no block-update tables.
Everything above is read-only.
drops — true, false and nil
drops is the field of a game block that a pack writes. It says whether a
block of this kind leaves its item when the world breaks it by itself: a
torch whose wall is gone, a leaf that decays, a block an explosion or a
piston breaks, sand that cannot land.
On a mode: lite world, the world leaves no such item. The pack switches a
block on:
citadel.yml: mode: lite
game.block("torch").drops = truegame.block("wall_torch").drops = trueprint(game.block("torch").drops)game.block("torch").drops = nil| Value | Meaning |
|---|---|
true |
The world leaves the block’s normal drops, on a lite world too. |
false |
The world leaves nothing for this block, with survival on too. |
nil |
The pack sets nothing. The world’s default applies. |
- The world’s default is off on a
mode: liteworld and in a room made byrooms.create. It is on on amode: fullworld and afterworld.rules{ survival = true }. - The value is for every state of the block, and for this block name only.
oak_planksandspruce_planksare two blocks. - It reads what this pack set, not another pack’s value. Where two packs
disagree,
falsewins. - It is not a player’s dig. Without
survival, a dig reaches no block. - Use it for the game’s blocks. A block from
game.blocks.defineleaves the drops its definition lists. - A reload removes a value that the script does not set again.
trueis an error in a game version with no items on the ground.
Items
game.item(name) does the same for items: the item’s table, or nil. It
never raises an error.
if game.item("bucket") then player:give("bucket") endprint(game.item("stone").stack_size)Entity kinds
A kind is a mob when the game gives it health and a mind of its own: a cow,
a zombie. An arrow, an item and a boat are not mobs. A player is not an
entity here: players are in players, never in world.entities. game.entities.<kind>
has the facts of one kind of the game. game.entities.cow and game.entities.Cow are the same
kind. A kind that this game does not have is nil:
if game.entities.creeper then.
local cow = game.entities.cow
print(cow.max_health, cow.width, cow.height, cow.speed) -- cow.health is an error: a kind has a maximum
print(cow.drop) -- "leather"
print(cow.hostile) -- false
print(cow.registry_name) -- "Cow", this version's own spelling
print(cow.mob) -- true: a cow is a mob
for name, kind in game.entities do -- every mob kind this version has, in its own order
if kind.hostile then print(name) end
end
local arrow = game.entities.arrow -- a kind that is not a mob has a row too
print(arrow.mob) -- false
print(arrow.width, arrow.height, arrow.physics)
game.entities.names() -- every kind: the pack's own and the game's, mob or not
game.entities.names { mob = true } -- the mob kinds only
game.entities.names { mob = false } -- the kinds that are not mobs
- Use
for name, kind in game.entities do, notpairs(game.entities). - A game kind that is not a mob (an arrow, a boat, primed TNT) has the facts
name,mob(false),width,heightandphysics("item","falling","vehicle"or"none"). Every other fact isnil. A write tospawn,attacksorinteractis an error, and so is:amend: they are for mob kinds. - Iteration and
game.entities.names()cover all kinds, once each. Usegame.entities.names { mob = true }or checkkind.mobfor mob settings. - A pack kind (
rave:rocket) reads as a definition handle, withnameandmob = false. Pass it toworld.spawnjust like the handle fromdefine. define,amendandnamesare functions on the same table (see “Custom entities”).game.entities.cow:amend { ... }is the same asgame.entities.amend("cow", { ... }).
Everything above is read-only.
Spawn rules — true, false and nil
spawn is the field of a mob kind that a pack writes. It says whether the
kind is in this world by itself.
On a mode: lite world, no mob spawns by itself. The pack switches
a kind on:
citadel.yml: mode: lite, game: "b1.7.3", world: overworld
game.entities.cow.spawn = trueCows now spawn by the game’s own rule. No other kind spawns. A player’s right click on a cow with a bucket gives milk.
game.entities.cow.spawn = falseprint(game.entities.cow.spawn)game.entities.cow.spawn = nilprint(game.entities.cow.spawn)| Value | Meaning |
|---|---|
true |
The kind is in this world as the game defines it. It spawns by the game’s own rule, and it is the game’s entity in full. |
false |
The kind never spawns by itself. |
nil |
The pack sets nothing. The world’s default applies. |
- The world’s default is off on a
mode: liteworld and in a room made byrooms.create: no mob spawns by itself. The default is on on amode: fullworld and afterworld.rules{ survival = true }: each kind spawns by the game’s own rule.world.rules{ survival = false }sets the default to off again. truemakes the kind the game’s entity in full, on a lite world too. It spawns by the game’s own rule. Its hits hurt players and a player’s right click on it has the game’s effect. See “attacksandinteract” below.- A monster that comes to a sleeping player obeys the same value.
truedoes not make a kind spawn where the game cannot spawn it. On 1.8.9 the game takes the kinds it spawns from the biome. A world with no biomes (a world the scripts make) spawns nothing, andtrueis an error there.falsestops natural spawning only. A spawner block,world.spawn,/summonand breeding still make the entity.- Mobs already in the world stay.
- Reading gives what this pack set:
true,falseornil. It does not give the game’s own rule or the value of a different pack. - Each pack has its own value. If one pack sets
false, the kind does not spawn. If no pack setsfalseand one pack setstrue, the kind is on. - The value is for one room.
gameis the main room’s table. A room fromrooms.createhas its own:room.game.entities.cow.spawn = true. - On a script reload, the values of the last run stay until the new script has loaded. Then each value that the new script did not set is removed.
- On a game with no natural spawning, every write is an error,
nilincluded. a0.1.0 to a0.1.3 are such games. - An error is a plain string for
pcall.
attacks and interact
attacks and interact are two more fields of a mob kind that a pack writes. Each is true,
false or nil. A different value is an error.
game.entities.zombie.attacks = falsegame.entities.cow.interact = falsegame.entities.zombie.attacks = nil| Field | true |
false |
|---|---|---|
attacks |
The entity’s hits hurt players. | The entity’s hits do not hurt players. |
interact |
A player’s right click on the entity has the game’s effect (milk from a cow, a saddle on a pig). | The right click has no effect. |
With nil, the engine uses the first line that applies:
- The kind has
spawn = true: the field is on. - The room’s rule:
damageforattacks,survivalforinteract.
- The kind’s own setting is stronger than the room’s rule. Thus
game.entities.zombie.spawn = truemakes a zombie’s hit hurt in a room withworld.rules{ damage = false }. To keep the zombie harmless there, setgame.entities.zombie.attacks = false. - A zombie from
world.spawnon a lite world does not hurt players until the pack setsspawn = trueorattacks = truefor zombies, or the room has thedamagerule. interactchanges the item in the player’s hand as the game does: an empty bucket becomes a bucket of milk.interactis not available on 1.8.9: that game version has no right click on a mob in Citadel.interact = trueis an error there, andspawn = truedoes not give the right click.attackscovers the entity’s own hit, its arrow and its blast. An arrow keeps the kind of its shooter, so the arrow of a dead skeleton followsgame.entities.skeleton.attacks. The blast of a creeper followsgame.entities.creeper.attacks.attacks = falsestops the damage to players only. The blast of a creeper still breaks blocks, as the game says, and still hurts other entities.- A blast of TNT, of a bed and of
world.explodehas no kind. It follows the room’sdamagerule. - The fields are for one room and one pack, as
spawnis. If one pack setsfalse, the field is off.
To put mobs in a world, use world.spawn(name, pos) (see “Mobs and
drops”), /summon, or a dungeon spawner the terrain placed.
a0.1.0 spawns nothing on its own. Only its dungeon spawner makes mobs.
Terrain
game.terrain describes this world’s overworld: snow, and steps in the
shape citadel.yml uses. It is read-only, and nil where the engine has no
list.
for i, step in ipairs(game.terrain.steps) do
print(i, step.step, step.block, step.count) -- 1 dungeons nil 8
end
print(game.terrain.snow) -- false