OOC:How to Code

A collection of tips, examples, and advice on working in PennMUSH code and learning how to use it.

Contents

Overall Tips

Where to start?

$-commands

help $-commands

These are the most basic building blocks of making something DO something. They're probably where the majority of people start in coding. PRO TIP: remember to set the object !no_command first. $-commands can be used for an infinite variety of things, but are basically ways to allow someone to interact with a room or object. The most basic $-commands are usually ways to trigger an @emit of the person interacting with the object. Examples you've seen on grid might include the taps at Leona's Bar & Girl - a fantastic basic $-command.

A sample basic command might be:

&cmd`knock here=$knock:@emit %n knocks at the door.

The &STUFF part is the name of the variable. Everything between the $ and the : is what is typed in for the command. A * represents a wildcard in this area, and can be referenced with %0 for the first *, %1 for the second, and so on. Everything after the : is what the command does.

More complicated $-commands can run all the way up to things like the Jusenkyou system. In general, figure that if you want a person to TYPE something to CREATE A RESPONSE, you want to use a $-command.

^-patterns

help ^

^ patterns are used to make an object listen for a specific pattern of speech and respond to it. They're how the vast majority of 'waitress' or 'shopkeeper' objects on the grid work. The object must be set MONITOR to pick up ^ patterns.

A sample ^ pattern might be:

&*CMD_AFTERNOON Kia=^*Kia*Afternoon Revival*:pose nods and smiles, turning to prepare %n's order. "Just one moment please." After a moment she hands %n the cup. "Careful, its hot. Please enjoy."

The beginning is the same as with $-commands or any other attribute. However, here, the ^ tells the object to listen for the string that follows. The * are, again, wild cards, but in this case, they mean 'we don't care what comes before or after, so long as it has these words in it'. Once again, anything after the : is what the object will do in response to the string.

In general, if you want to respond to what someone SAYS or POSES, you want to use a ^-pattern.

Functions

Functions are for... almost anything else. They're too huge to cover more than very generally, but roughly speaking, a function EVALUATES a CONDITION and responds to it. Examples might be rooms that show different descs based on time of day, how a multidescer shows a different desc is you change a particular attribute, etc. To use functions well, you will be doing a lot more trial and error until you learn them, will need to read help files extensively, and will get very, very familiar with checking for matching brackets.

Probably the most commonly used functions are u() and switch(), and if you want to start out more about using functions, I'd suggest starting there. We also have our local custom weather() function, which is extremely useful in descing.

Retrieved from "https://www.yuriba.com/mwiki/index.php?title=OOC:How_to_Code&oldid=10176"