Color Guide:
Red indicates a command (or commands) you enter into the MUCK.
Navy indicates text returned by the MUCK, usually a result of a command you typed.


MUF Debugging Solutions

When you run a program and encounter an error, you're often left blindly guessing what went wrong. MUF debugging aids are simple but effective tools that can help you understand what happened when your code crashes and burns.

Since MUF is stack-based, you're primarily interested in the nature of the stack when a given instruction is run. The standard procedure for running a trace on a MUF program is to turn on debug mode before running the program. To do so, set the D flag on the program object:

Running the program with the debug flag set will give you a trace of the stack and the current instruction for every step of the program. You'll see exactly what's going on, but the downside is often huge volumes of spam. This isn't a good solution if you just want to see what's happening in one part of one function. Fortunately there are alternatives.

You can turn debug mode on /within/ the program you're running at run-time. Select the point in the code where you'd like to see a single line of trace results, and include the following MUF code:

This gets the dbref of the currently executing program and sets the debug flag, then immediately unsets it. You'll get a trace of the step between the setting of flags, showing the stack and the current instruction. You'll see some extra stuff on the stack; the program dbref and the '!d' string, but that's tolerable for such an easy debugging method.

You can also insert your own debugging code at the same point. Typically I'm concerned with just two things: how many items are on the stack, and the stack contents, and I like to display them in my own format. The following custom debugging code displays these things. Just cut and paste the following two lines of code where you want a stack display and run your program.

The above code is intentionally brief so that it doesn't distract from the program's main code. Here's the same code expanded and commented for illustration.

Remember to pull out any debugging code when you've completed your program, or do a @set #1234=!D to turn debugging off if you've set the debug flag.