Manual:Zone Manual/The Objects Section/Compiling and Debugging your first object

From DikuMUD Wiki
< Manual:Zone Manual‎ | The Objects Section
Revision as of 06:18, 15 November 2026 by Agent-mud (talk | contribs) (checked against the current code (wiki review 2026-11-15))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Compiling and debugging your first object

As with rooms and NPCs, build one or two things and then compile, so that errors are easy to find. Here we compile the dragon head on its own, in a zone that has only an %objects section. The file is debug_obj.zon, so the zone is called debug_obj: the zone name must be the file name.

This version has mistakes in it on purpose. We also decided players should be able to club each other with the head, so it got a WEAPON_DEF:

#include <macros.h>

%zone debug_obj
lifespan 20
reset RESET_ANYHOW
creator {"whistler"}

%objects

dragon_head
names {"large golden dragon head", "large gold dragon head,
       "golden dragon head", "gold dragon head", "large dragon head",
       "dragon head", "large head", "sad head", "head"}
title "a gold dragon head."
descr "A large golden dragon head is lying here, looking sad."
WEAPON_DEF(WPN_CLUB, 10, 0)
manipulate MANIPULATE_TAKE, MANIPULATE_HOLD
weight 60
height 90

extra {}
"The head is large and beautiful, at least as beautiful as a dead dragon
head can be. There is a look of deep sorrow on the dragon's face, and it
seems to be about much more than its own death."

extra {"$get_s"}
"You suddenly feel very sad for a world that you don't even know."

extra {"$get_o"}
"A strange look of sadness crosses $1n's face."
end

%end

Copy it into vme/zone/ if you want to follow along. Compile it from that directory:

cd vme/zone
../bin/vmc -d ../etc/ -I../include/ debug_obj.zon

-d says where the money file is and -I where the include files are. The options are explained in General Compiler Information. The first try gives:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'debug_obj.zon'
<debug_obj.zon> @ 35: EOF in string
v: debug_obj.zon: 6: syntax error
   Token: '{'
v: debug_obj.zon: 12: syntax error
   Token: 'golden'
Grave errors in file 'debug_obj.zon'.

(The date in the first line is the day your vmc was built.) A syntax error gives the line number and the token where vmc got stuck. Always fix the error with the lowest line number first: one mistake often causes others further down.

The first error is on line 6, at the {. Nothing is wrong with the brace: vmc doesn't know the word before it. The field is creators, not creator. Fix it and compile again:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'debug_obj.zon'
<debug_obj.zon> @ 35: EOF in string
v: debug_obj.zon: 12: syntax error
   Token: 'golden'
Grave errors in file 'debug_obj.zon'.

Line 12 looks right, and "EOF in string" says that a string runs on to the end of the file. When a correct-looking word is the error, look for a missing " or brace before it. Here it is on line 11: "large gold dragon head, has no closing quote, so the string ends at the next ", and vmc then finds the word golden where it expects a comma. Add the quote before the comma:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'debug_obj.zon'
v: debug_obj.zon: 17: syntax error
   Token: ','
Compilation aborted.

Line 17 is the manipulate field. A single flag needs no braces, so vmc reads manipulate MANIPULATE_TAKE and then doesn't know what to do with the comma. Several flags must be in braces: manipulate {MANIPULATE_TAKE, MANIPULATE_HOLD}. Compile again:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'debug_obj.zon'
WARNING: dragon_head: Title ends with non-alphabet character 'a gold dragon head.'
FATAL: Illegal bonus (-7..+7 allowed) in 'dragon_head'.
WARNING: Fatal errors in zone.

The syntax is right now, and vmc checks the values. These messages have no line numbers; they name the object instead, and vmc also writes them to debug_obj.err. The fatal error is the craftsmanship of 10 in WEAPON_DEF: bonuses go from -7 to +7 (see Object macros). Use the names from values.h and you can't get the number wrong: WEAPON_DEF(WPN_CLUB, BONUS_GOOD, BONUS_AVERAGE).

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'debug_obj.zon'
WARNING: dragon_head: Title ends with non-alphabet character 'a gold dragon head.'
VMC Done.

"VMC Done." means the zone compiled: vmc wrote debug_obj.data and debug_obj.reset. The warning doesn't stop it, but a title shouldn't end in a full stop: the game puts titles in the middle of sentences ("You get a gold dragon head."). With -l warnings count as errors, and the compile fails:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'debug_obj.zon'
WARNING: dragon_head: Title ends with non-alphabet character 'a gold dragon head.'
WARNING: Fatal errors in zone.

Remove the full stop, and the compile is clean:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'debug_obj.zon'
VMC Done.

What vmc doesn't catch

A clean compile doesn't mean the object works. vmc doesn't check:

  • references to other units: a key that doesn't exist, or a dilcopy template with the wrong name or arguments. They show up when the zone boots, in vme/bin/vme.log, or when the object is used.
  • flags of the wrong kind: flags {OBJ_NO_DUAL} compiles, and sets a unit flag with the same number (the object loads buried). Object flags go under romflags.
  • a missing $: extra {"drop_o"} compiles as a description of something called "drop_o", and the message never appears.
  • a missing MANIPULATE_TAKE, a container without MANIPULATE_ENTER, or armour without a wear position. They compile, and players can't take, fill or wear the object.

A failed compile leaves the previous .data and .reset files in place, and the server loads those without a word. Check that vmc ended with "VMC Done.".

Into the game

The server reads zones only when it boots:

  1. A new zone needs a line in vme/etc/zonelist; copy one of the lines there and change the name.
  2. Restart the server (vme) and look in vme/bin/vme.log for lines about your zone.
  3. Log in as an administrator and load the object by its symbolic name and zone: load dragon_head@debug_obj. wstat dragon_head@debug_obj shows its fields, and wstat zone debug_obj objects lists the objects of the zone.

Play with the head a little: pick it up, drop it, hold it, look at it and at its face. Then you are ready for More complex objects.

If you are stuck on an error, take a break, or ask someone else to look: a fresh pair of eyes often finds a missing quote in seconds. Breaking a zone that compiles on purpose, as we did here, is a good way to learn what the messages mean.

Previous: Building your first object
Next: DIL functions for objects