Now before you read all of this, remember that this is only an example of MOOcode and how to write into the Verb Editor. This does not explain MOOcode or object oriented concepts in any detail. Hopefully you've already done the MOOmail tutorial so things are very familar.
In order to make a verb work, you need an object to put it on.
@create $thing called BatThen you need to add the verb to it.
@verb Bat:hit any with this rxdAnd then enter the Verb Editor to start programming the verb.
@edit Bat:hit Verb Editor Do a 'look' to get the list of commands, or 'help' for assistance. A place in cyberspace where the coders roam. Now editing #2174:hit (any with/using this). "if (this.location != player) Line 1 added.... you must always use a quote ( " ) symbol at the beginning (like say) to add a new line into the verb editor ...
"player:tell("You do not have ",this:title(),".");
Line 2 added.
"elseif (#20:match_object(dobjstr, player.location) == $failed_match)
Line 3 added.
"player:tell("I won't let you swing and miss. '",dobjstr,"' isn't here.");
Line 4 added.
"elseif (!dobjstr)
Line 5 added.
"player:tell(wrong);
Line 6 added.
... Just adding relevent lines of code ...
print
if (this.location != player)
player:tell("You do not have ",this:title(),".");
elseif (#20:match_object(dobjstr, player.location) == $failed_match)
player:tell("I won't let you swing and miss. '",dobjstr,"' isn't here.");
elseif (!dobjstr)
player:tell(wrong);
--------------------------
... This shows us what we've done so far ...
previous __6_ player:tell(wrong); prev __5_ elseif (!dobjstr)... to move backwards, up the code, you can use 'previous' or shorter versions, for minimum key strokes ...
p
__4_ player:tell("I won't let you swing and miss. '",dobjstr,"' isn't here.");
p
__3_ elseif (#20:match_object(dobjstr, player.location) == $failed_match)
p
__2_ player:tell("You do not have ",this:title(),".");
p
__1_ if (this.location != player)
p
____
"wrong = tostr("Correct Syntax: hit
Line 1 added.
... Inserting line 1, so this variable will work throughout the verb ...
next
^^3^ player:tell("You do not have ",this:title(),".");
... using 'next' or shorter travels down the editor, notice how it
gives the line after the one we are at ...
n
^^4^ elseif (#20:match_object(dobjstr, player.location) == $failed_match)
n
^^5^ player:tell("I won't let you swing and miss. '",dobjstr,"' isn't here.");
n
^^6^ elseif (!dobjstr)
n
^^7^ player:tell(wrong);
n
^^^^
... Now to add more relevent code, starting at line 8 ...
"else Line 8 added. "player:tell($string_utils:pronoun_sub(this.personhit_msg)); Line 9 added. s/$string_utils/#20... 's' is substitution, for it is shorter to use #20 than $string_utils ...
__9_ player:tell(#20:pronoun_sub(this.personhit_msg)); s/pronoun_sub/psub... within AussieMOO, pronoun_sub has an verb alias 'psub', so we'll use that ...
__9_ player:tell(#20:psub(this.personhit_msg)); "else Line 10 added. del else ---Line deleted. Insertion point is before line 10.... Whoops, made a mistake, 'del' deletes the line we last did ...
"dobj:tell(#20:psub(this.dhit_msg));
Line 10 added.
"player.location:announce_all_but({player,dobj},#20:psub(this.ohit_msg));
Line 11 added.
"endif
Line 12 added.
com
#2174:hit successfully compiled.
... Some more code, and a 'com' command to compile the program ...
print
wrong = tostr("Correct Syntax: hit
... A nice piece of code, the indents are done automatically, and now out of
the verb editor ...
Archwiz'z Resting Room A small room, entirely made with softness on the mind...... Quite misty and calming...... You notice lots of small silky pillows covering the floor. The pillows are just scattered about calmly. You see The Bunny Bar here. Obvious exits: down to FutureTec Inc. (#181) box to Cat-Box (#1881) passage to Shadar Logoth (#1206) @prop bat.personhit_msg "You clobber %d over the head with your %t." rc Property added with value "You clobber %d over the head with your %t.". @prop bat.dhit_msg "%N clobbers YOU with %p %t!" rc Property added with value "%N clobbers YOU with %p %t!".... add those _msg properties, with string values, substitutions, and permissions ...
@prop bat.ihit_msg "%N clobbers %d over the head with a %t!" Property added with value "%N clobbers %d over the head with a %t!". @rmprop bat.ihit_msg Property removed.... Oops, wrong prop name, we'll have to remove it ...
@prop bat.ohit_msg "%N clobbers %d over the head with a %t!" Property added with value "%N clobbers %d over the head with a %t!".... Last correct prop added, now it should work, don't be TOO violent ...
Back to Main