� Mana Pyre | Main | Harry Potter mania �

July 18, 2005

MUD Ideas

Small Tutorial ala the seal

Meathe has been hammering down new code for room/object programs and squashing bugs in the current mob program system. I had asked for this tutorial from him, as he's quite good at pointing out where I have made an error. By rights it belongs on his site (go to Musings, Meandering to check out his site) but I'm going to throw it up here so I don't lose it myself. Mine own computer seems to have a propensity to wait for those occasions to lose information:

As written by Meathe on 7/18/2005

The mprog interpretter is a fussy little beast, and if the code isn't precisely how it expects it, it will throw a hissy fit and lock up.

This will be fixed soon, but, even so, if it's not how it wants it, the
program will not run as expected.

IF ELSE ENDIF

The if statement is fairly straight forward, but very, very fussy. Every
IF needs an ENDIF.

The basic form is IF (condition) (arguments) /ELSE/ ENDIF

So if you want a goblin to say hello to people under level 15, the code
would be:

IF level $n <= 15
say Hello there, newbie.
ENDIF

If, however, you want it to laugh at everyone over level 15 as well, you
need the else statement. The else statement is still part of the IF, it
needs to be between the IF and ENDIF

IF level $n <= 15
say Hello there, newbie.
ELSE
laugh $n
ENDIF

Nesting them can get messy, and you need to keep track of where you
are. To extend the program above to laugh at everyone over level 15 and
not immortals, you need to nest the if statements, like this.
(The indented stuff in brackets is (hopefully) to make it visually
easier to see how they actually execute and not part of the program)

IF level $n <= 15 (First IF)
say Hello there, newbie. ....
ELSE (Else)
IF level $n > 101 (Second IF)
say Oh my god! ....
ELSE (Else for Second IF)
laugh $n ....
ENDIF (EndSecond)
ENDIF (EndFirst)

If you nest them, then the innermost IF (most recent one) is ended
first. You can nest up to 5 IF statements.


REMEMBER & FORGET
The mob will remember the name of the character ($q) and the name and
title or short desc ($Q) for use in later mprogs.

The trusty goblin Has the following mprogs:
[ 0] 158 greet 100
[ 1] 159 speech hello

mpdump 158
say I'll remember you, $n!
mob remember $n

mpdump 159
if name $n==$q
say Ah, I remember you, $Q!
mob forget $Q
endif

When a character enters the room, the goblin will remember his/her
name. If the character then says 'hello', the second program is kicked
off. If the character was the last to enter the room (and thus is
remembered), the program will say I remember you and promptly forgets
the character. If the character says hello again (without leaving and
reentering), nothing happens.


DELAYS:
There are two parts to a delay action,

The mprog code:

mob delay (number) The number is measured in 1/15ths of a tick.

And the trigger, DELAY, used to attach the program to fire after the delay.

Here we have three mprogs on the old crash test goblin.


Goblin:
[ 0] 160 greet 100
[ 1] 161 exit 0
[ 2] 162 delay 30


mpdump 160
say Hello $n!
mob remember $n

mpdump 161
say Goodbye, $q!
wave
mob delay 30

mpdump 162
say That $Q was a bit of a prick, really.
mob forget $q

The first one will fire as someone enters the room, say Hello and
remember the character.
The second prog will fire if the character leaves north, saying goodbye
and waving. And sets the delay timer for two ticks.

After which, 162 fires, saying something mean, then forgetting the
character.

Posted by Ravennacht at July 18, 2005 06:55 PM Posted to MUD Ideas