
Home - Forum - Code - Articles - Links - Files
Over the years of programming MUF code, people have found the same tasks come up over and over again: notifying a string to the user, or seeing if a string means yes.
Fuzzball provides the MUF macro facility just for these cases, and here are some basic common macros.
A MUF macro is a shorthand string (called with .macro in your MUF program) that gets expanded to more code when the MUF is compiled. They're kept in the macros file in a Fuzzball muck's game/muf directory. Macros are managed with the following three commands in the MUF editor:
def macro code.macro--a period followed by the name of the macro--in a program instead of code.[macro] sshow command lists all defined macros with names starting with macro. For example, notify s might list notify_nospam, notify_exclude_nospam, notify_except_nospam, and others. If macro is not given, show lists all defined macros.macro kkill command undefines a macro. Only wizards can remove macros, so don't go adding them willy-nilly (unless, of course, you're a wizard).The problem with macros is that people tend to not notice when they're installed, and install the same or slightly different code over and over with different macro names. Some of the macros named below are named as an attempt to standardize the name you'll find them under on different mucks--muck owners should consider cleaning out other versions, and/or redefining them in terms of some other macro that does the same thing.
The macros are nicely spaced out for viewing below, but the list is also provided in pastable script form for easy uploading. The collapsed versions in the script include comments with \n and \t, describing how to break them back into their readable forms.
[And not only is there this list of macros, but at least two others: Ginger's from FurToonia and the fbmuf list at Mink. --Natasha, 18 August 2001]
: abs ( int -- int' } Returns the absolute value of the given integer. )
dup 0 < if -1 * then ( int' )
;
: singlespace ( str -- str' } Change all runs of multiple spaces in the given string to single spaces. )
begin dup " " instr while ( str ) subst ( str' ) repeat ( str' ) ;
: notify_except_nospam ( dbRoom dbPlayer strMessage -- } Notify everyone in the given room, except the given player and anyone who's _nospam?:yes, of the given string. )
1 swap .notify_exclude_nospam ( )
;
: notify_exclude_nospam ( dbRoom dbP1..dbPn intN strMessage -- } Notify everyone in the given room, except the given players and anyone who's _nospam?:yes, of the given string. )
( Fetch dbRoom; that's intN plus three {intN, strMessage, and down one more}. )
over 3 + pick ( dbRoom dbP1..dbPn intN strMessage dbRoom )
( Loop through its contents. )
contents begin dup ok? while ( dbRoom dbP1..dbPn intN strMessage dbContained )
( Is this object _nospam?:yes? )
dup "_nospam?" getpropstr .yes? if ( dbRoom dbP1..dbPn intN strMessage dbContained )
( Yes; add it to the exclusion list. )
dup -4 rotate ( dbRoom dbP1..dbPn dbContained intN strMessage dbContained )
rot 1 + -3 rotate ( dbRoom dbP1..dbPn' intN' strMessage dbContained } dbContained is the new dbPn, and intN is incremented. )
then ( dbRoom dbP1..dbPn intN strMessage dbContained )
next repeat pop ( dbRoom dbP1..dbPn intN strMessage )
( Notificate. )
notify_exclude ( )
;
: tell ( str -- } Notify the user of the given string. )
me @ swap notify ;
: otell ( str -- } Notify everyone in the room except the current user of the given string. )
loc @ me @ rot notify_except ;
: alltell ( str -- } Notify everyone in the room {including the user} of the given string. )
loc @ 0 rot notify_exclude ;
pop macros: popall ( .. -- } Removes everything on the stack. )
begin depth while pop repeat ( )
;
: popn ( ??N..??1 intN -- } Removes a list of intN items {ie, the top intN+1 things} from the stack. )
dup 0 > if begin dup while ( ??N..??1 intN )
swap pop ( ??N..??2 intN )
1 - repeat then pop ( } Putting the pop outside the if-then pops intN even if 0 or negative. )
;
: wiz? ( db -- bool } Returns true if the given dbref has wizardly powers {ie, has a wizbit and isn't Quelled}. )
dup "W" flag? if ( db )
"Q" flag? not ( bool )
else pop 0 then ( bool )
;
: wizard? ( db -- bool } Returns true if the given dbref has a wizbit. )
"Wizard" flag? ( bool )
;
: yes? ( str -- bool } Returns true if str starts with 'y' or '1'. )
dup if
1 strcut pop ( str- )
dup tolower "y" strcmp if ( str- )
"1" strcmp not ( bool )
else pop 1 then ( bool )
else pop 0 then ( bool )
;
: no? ( str -- bool } Returns true if str is null, or starts with 'n' or '0'. )
dup if
1 strcut pop ( str- )
dup "n" strcmp if ( str- )
"0" strcmp not ( bool )
else pop 1 then ( bool )
else pop 0 then ( bool )
;