Docs · defs

defs

9 defs commands, generated from the engine's own registry — signatures, parameters and a worked example each. A does something command acts on the game; a needs x() one answers a confident wrong answer when its client hooks are missing.

defHasCommand returns bool
defHasCommand(what: def, command: string) -> bool

Whether a definition offers this menu option, in either of its two slots. What the cache says the thing can do, which is not the same as what it offers right now - a door that is already open says Close.

ParameterTypeWhat it does
whatrequired def the definition
commandrequired string the menu option, case ignored
Example
if defHasCommand(objectDef(1), "Chop down") { print("choppable") }
defNameContains returns bool
defNameContains(what: def, fragment: string) -> bool

Whether part of a definition's name matches.

ParameterTypeWhat it does
whatrequired def the definition
fragmentrequired string part of the name, case ignored
Example
if defNameContains(itemDef(151), "ore") { print("some kind of ore") }
defNamed returns bool
defNamed(what: def, name: string) -> bool

Whether a definition has exactly this name. The whole name, not a prefix - "Iron ore" is a prefix of "Iron ore certificate" and picking one for the other is the mistake this avoids.

ParameterTypeWhat it does
whatrequired def the definition
namerequired string the whole name, case ignored
Example
if defNamed(itemDef(151), "Iron ore") { print("that is the one") }
defsAvailable returns bool
defsAvailable() -> bool

Whether the game cache has been mapped. False means every definition comes back unknown, so a script that matches things by name would quietly find nothing rather than fail.

Example
if not defsAvailable() { print("no names this session") stop }
itemDef needs defsAvailable() returns def
itemDef(id: int) -> def

What the cache says about an item id. Never none: an id the cache has nothing for comes back with .known false and an empty name.

ParameterTypeWhat it does
idrequired int the item id
Example
print("item 10 is", itemDef(10).name)
itemDefCount needs defsAvailable() returns int
itemDefCount() -> int

The size of the item-definition list - the sweep bound for enumerating the cache with itemDef(id), whose ids run 0 to one less than this. 0 when the cache has not been mapped, so an unmapped session sweeps nothing rather than failing.

Example
let n = itemDefCount()  # sweep ids 0..n-1 with itemDef(id)
npcDef needs defsAvailable() returns def
npcDef(id: int) -> def

What the cache says about an npc id. Never none: an id the cache has nothing for comes back with .known false and an empty name.

ParameterTypeWhat it does
idrequired int the npc id
Example
print("npc 1 is", npcDef(1).name)
objectDef needs defsAvailable() returns def
objectDef(id: int) -> def

What the cache says about an object id. Never none: an id the cache has nothing for comes back with .known false and an empty name.

ParameterTypeWhat it does
idrequired int the object id
Example
if objectDef(1).command1 == "Chop down" { print("a tree") }
wallDef needs defsAvailable() returns def
wallDef(id: int) -> def

What the cache says about a wall or door id. Never none: an id the cache has nothing for comes back with .known false and an empty name.

ParameterTypeWhat it does
idrequired int the wall or door id
Example
print("wall 2 is", wallDef(2).name)