home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games (Alt) / INFESPGAMES.iso / os2 / backgam / source / examples < prev    next >
Encoding:
Text File  |  1992-08-20  |  11.8 KB  |  322 lines

  1.                    Interesting and useful macros
  2.  
  3.  
  4. This examples document assumes you have read the helpfile sections 
  5. on macros, triggers, substitution and reentrance.  They are 
  6. intended as illustrations of the ways in which Fugue macros can be 
  7. used, and as a tutorial in the use of these features.
  8.  
  9. The examples given here are intended to be used with /load.  When a
  10. file is read with /load, lines beginning with ';' are ignored, and
  11. lines ending with '\' will have the following line appened to it after
  12. leading spaces are stripped.
  13.  
  14. For reference, OUTPUTPREFIX and OUTPUTSUFFIX are MUD commands that set
  15. prefixes and suffixes for output that stems from a MUD command (such as
  16. look, WHO, etc.)  A "one-shot" trigger is a trigger that will remove
  17. the associated macro (and thus the trigger) upon being hit once, i.e.
  18. it only functions once.  (This is the "-1" switch.)
  19.  
  20. A note: The OUTPUTPREFIX and OUTPUTSUFFIX commands are not supported on
  21. all MUDs.  There are other, somewhat less reliable methods for
  22. prefixing and sufixing commands that may be utilized by the reader.
  23.  
  24. The priority numbers used in here have no special meaning; a 
  25. priority of 50 is used for triggers that continually exist (this is 
  26. to override /hilites and /gags of lower priority) and a priority of 
  27. 100 or 101 is used for temporary triggers must work for the macros 
  28. to properly complete.
  29.  
  30. WATCH
  31. -----
  32.  
  33. /def pfxon = OUTPUTPREFIX <!pre>%;OUTPUTSUFFIX <!suf>
  34. /def pfxoff = OUTPUTPREFIX%;OUTPUTSUFFIX
  35. /def pcmd = /pfxon%;%*%;/pfxoff
  36.  
  37. /def watch = \
  38.   /def watch_%1 = \
  39.     //pcmd WHO %%;\
  40.     //def -p100 -1 -ag -t"<!pre>" = \
  41.       ///watch_make %1 %;\
  42.   /repeat -60 10000 //watch_%1
  43.  
  44. /def watch_make = \
  45.   /def -p100 -ag -t"*" watch_tmp1_%1 %;\
  46.   /def -p101 -ag -t"%1 *" watch_tmp2_%1 = \
  47.     //echo <!> %1 is connected. %;\
  48.   /def -p101 -1 -ag -t"<!suf>" = //purgedef watch_tmp?_%1
  49.  
  50. These two macros will simulate a /watch command, like KnightSkye's 
  51. client.  Every minute it will check the WHO list to see if a given
  52. user is connected to the current MUD or MUCK.  To step through it, 
  53. I'll use as an example "/watch chup"
  54.  
  55. First, TF substitutes for newlines.  Every sequences "%;" is changed
  56. into a newline.  The %%; sequences are left alone.  Thus the two
  57. commands (starting with a single '/) after "/def watch=" are processed
  58. separately.
  59.  
  60. Second, TF checks for reentrant commands.  Both lines contain commands,
  61. so these are all processed.  Before they are processed, two things
  62. occur: first, all multiple "/" sequences are compressed by one, and
  63. second, argument substitution is done.  The "%1"s are substituted with
  64. "chup".  Multiple "%"s are compressed by one in this process.  Thus
  65. the two commands to be executed are:
  66.  
  67.     /def watch_chup = /pcmd WHO%;/def -1 -ag -t"<!pre>" = //watch_make chup
  68.     /repeat -60 10000 /watch_chup
  69.  
  70. This sets up the watch macro and tells TF to execute it 10000 times, once
  71. every sixty seconds.
  72.  
  73. Every sixty seconds, then, the following will occur:
  74.  
  75. Newline substitutions occur.  The body of /watch_chup is broken up into
  76. two lines.
  77.  
  78. Reentrance substitutions occur.  The command "/pcmd WHO" is executed,
  79. which in turn sends the following to the MUD:
  80.  
  81.     OUTPUTPREFIX <!pre>
  82.     OUTPUTSUFFIX <!suf>
  83.     WHO
  84.     OUTPUTPREFIX
  85.     OUTPUTSUFFIX
  86.  
  87. The actual process is more complex, but self-explanatory.
  88.  
  89. The fourth line is executed as a /def command, after the "//" is
  90. compressed:
  91.  
  92.      /def -p100 -1 -ag -t"<!pre>" = /watch_make chup
  93.  
  94. The macro is now completed, and returns control to the main program,
  95. where things continue normally.  Shortly afterwards, the line "<!pre>"
  96. should be received from the MUD, marking the beginning of the WHO list.
  97. The line "/watch_make chup" is now executed.
  98.  
  99. After all substitutions, TF comes up with the following commands:
  100.  
  101.      /def -p100 -ag -t"*" watch_tmp1_chup
  102.      /def -p101 -ag -t"chup *" watch_tmp2_chup = /echo <!> chup is connected.
  103.      /def -p101 -1 -ag -t"<!suf>" = /purgedef watch_tmp?_chup
  104.  
  105. Control is then returned to the main progam.  All following lines are
  106. gagged, so the user does not see the WHO list.  Any line beginning with
  107. "chup *" will set off the command /echo <!> chup is connected., informing
  108. you that he is online.   The line "<!suf>" marks the end of the WHO list,
  109. purging the other two gags.  Since that trigger is a one-shot trigger, it
  110. also deletes itself.
  111.  
  112. The net result is that every sixty seconds a WHO list is received from
  113. the MUD with all lines gagged, except for a notification message when
  114. chup is on-line.  Temporary triggers are created and discarded as
  115. necessary; only the /watch_chup macro is permanent.
  116.  
  117. The /mecho output for "/watch Xeglon" would look like so (blank lines
  118. signify control was passed to the main program and that the next block
  119. is as a result of a trigger going off).
  120.  
  121. <m> /def watch_Xeglon = /pcmd WHO %;/def -p100 -1 -ag -t"<!pre>" =
  122. //watch_make Xeglon
  123. <m> /repeat -60 10000 /watch_Xeglon
  124.  
  125. <m> /pcmd WHO 
  126. <m> /pfxon
  127. <m> OUTPUTPREFIX <!pre>
  128. <m> OUTPUTSUFFIX <!suf>
  129. <m> WHO
  130. <m> /pfxoff
  131. <m> OUTPUTPREFIX
  132. <m> OUTPUTSUFFIX
  133. <m> /def -p100 -1 -ag -t"<!pre>" = /watch_make Xeglon
  134.  
  135. <m> /watch_make Xeglon
  136. <m> /def -p100 -ag -t"*" watch_tmp1_Xeglon 
  137. <m> /def -p101 -ag -t"Xeglon *" watch_tmp2_Xeglon = /echo <!> Xeglon is connected. 
  138. <m> /def -p101 -1 -ag -t"<!suf>" = /purgedef watch_tmp?_Xeglon
  139.  
  140. <m> /echo <!> Xeglon is connected.
  141.  
  142. <m> /purgedef watch_tmp?_Xeglon
  143.  
  144.  
  145. RWHO
  146. ----
  147.  
  148. Many muds send WHO information to a central RWHO server.  You can use tf
  149. to connect to this server:
  150.  
  151. /addworld rwho moebius.math.okstate.edu 6889
  152. /def rwho = /world rwho
  153.  
  154. Then you can see who's on what muds just by using the /rwho macro.  The
  155. address of the RWHO server above is current as of TF 2.1, but is subject
  156. to change.
  157.  
  158. As another example of macro usage (or for use with MUDs not cooperating with
  159. the RWHO server), here's a way to simulate RWHO.
  160.  
  161. Define the /pfxon, /pfxoff and /pcmd macros as above.
  162.  
  163. /def rwho2 = \
  164.   /def oworld = $world_name %;\
  165.   /world -%1 %;\
  166.   /pcmd WHO %;\
  167.   /def -p100 -ag -t"*" rwho2tmp%1 %;\
  168.   /echo WHO list for world %1: %;\
  169.   /def -p101 -1 -ag -t"<!pre>" = \
  170.     //undef rwho2tmp%1 %;\
  171.   /def -p101 -1 -ag -t"<!suf>" = \
  172.     //dc %%;\
  173.     //world $$oworld %%;\
  174.     //undef oworld
  175.  
  176. This macro connects (or switches) to another world, issues the WHO 
  177. command, waits until the output is done, and returns to the current 
  178. world.  (It also disconnects from the remote world, which may be 
  179. undesirable.)  As an example, consider "/rwho2 brig" done while in a 
  180. world "peg".
  181.  
  182. Newline substitutions occur, so every line is processed 
  183. separately.  All the lines are commands, so they are processed.  
  184. The first command, notably, contains a substitution symbol ('$')-- 
  185. the text "$world_name " is substituted with the name of the current 
  186. world ("peg").  Thus the first command is "/def oworld = peg".  The 
  187. second is "/world -brig", switching to the world "brig" without 
  188. logging in.  "/pcmd WHO" is then executed, telling the MUD to send 
  189. a prefixed and postfixed WHO list.  Then "/def -ag -t"*" 
  190. rwho2tmpbrig", suppressing all output from the MUD before the WHO 
  191. list.  A heading message is echoed, and then the triggers are set up:
  192.  
  193.      /def -p101 -1 -ag -t"<!pre>" = /undef rwho2tmpbrig
  194.      /def -p101 -1 -ag -t"<!suf>" = /dc %;/world $oworld %;/undef oworld
  195.  
  196. When the prefix is received, TF will stop gagging text, and the WHO 
  197. list will proceed as per normal.  When the suffix is received, TF 
  198. will disconnect.  The "$oworld " goes to the body of the macro 
  199. "oworld", which is "peg", so that command is "/world peg", 
  200. returning you to the previous world.  Finally, the macro "oworld" 
  201. is undefined, in order to clean up.  (The triggers themselves are 
  202. one-shot, so they do not need to be removed.)
  203.  
  204.  
  205. AUTORETURN AND SILENT MOVE
  206. --------------------------
  207.  
  208. The /pfxon and /pfxoff macros are required.  Most of this macro is 
  209. simply recognizing when you are killed, not actually returning.
  210.  
  211. /def -p50 -t"{*} killed you!" autoreturn =
  212.   /def -ag -p101 -t"Your insurance policy *" r1tmp1 =
  213.     //purgedef r1tmp* %%;
  214.     //def -ag -p101 -t"<Title of your home here>" r2tmp1 = 
  215.       ///purgedef r2tmp* %%%;
  216.       ///return %%;
  217.     //def -p100 -t"*" r2tmp2 =
  218.       ///purgedef r2tmp* %;
  219.   /def -p100 -t"*" r1tmp2 = //purgedef r1tmp*
  220.  
  221. /def pmcmd = /pfxon%;/%*%;/pfxoff
  222. /def ret = <path back to place to return to here>
  223. /def return = /pmcmd ret %;/echo <!> Returned.
  224. /def -ag -p50 -t"<!pre>" = /def -p49 -ag -t"*" gptmp
  225. /def -ag -p50 -t"<!suf>" = /undef gptmp
  226.  
  227. This is one way to set up a "silent" autoreturn.  It can't be 
  228. spoofed by people who don't know what the room you live in is.  
  229. (Note that since the "<!pre>" and "<!suf>" triggers remain on all 
  230. the time, it may be best to change these to something secret in 
  231. odrer to keep people from being able to spoof you into gagging 
  232. everything.)  When killed, you see only the lines "<person> killed 
  233. you!" and "<!> Returned."
  234.  
  235. This autoreturn, of course, only works on one MUD and for one place 
  236. in that MUD, unless you redefine /ret each time you go somewhere.  
  237. One way to make an autoreturn that is not MUD-specific is to 
  238. replace the /return macro with:
  239.  
  240. /def return = /pmcmd ret$world_name$ %;/echo <!> Returned.
  241.  
  242. Now, if you are connected to, say, the world "asylum", you can do 
  243. /def retasylum = e%;e to get to the town square (if you live in the 
  244. padded cell), for instance.
  245.  
  246. The /pmcmd macro is needed to do multiple commands with /pfxon and 
  247. /pfxoff because TF does not send arguments through newline 
  248. substitution.  However, you can get around the order of argument 
  249. processing by defining a macro as the arguments and using the macro 
  250. rather than the arguments directly.  As an example of how this can 
  251. be utilized, we can create a "silent move" macro utilizing the 
  252. macros and triggers in the autoreturn above:
  253.  
  254. /def move = /def mvtmp = %* %;/pmcmd mvtmp %;/undef mvtmp
  255.  
  256. This macro, assuming you have the /pmcmd macro set up properly and 
  257. the triggers to gag command output (the last two lines from the 
  258. autoreturn example) will allow you to move around within a MUD 
  259. without seeing the resulting output.  This is useful for 
  260. commonly-travelled paths.  While the macro looks very simple, it 
  261. actually nests several levels.
  262.  
  263.  
  264. COLOR HILITING
  265. --------------
  266. /def blue = /gag %* = //echo -w %e[34m%%*%e[0m
  267.  
  268. This macro is quite straightforward.  The command is extracted:
  269.  
  270.      /gag <args> = /echo -w <ESC>[34m%*<ESC>[0m
  271.  
  272. This simply gags whatever aguments the /blue macro is given, 
  273. instead echoing them prefixed and suffixed by appropriate ANSI 
  274. sequences.  The -w option to /echo prints the text to the history
  275. queue of the current world, rather then directly to the screen.
  276. Macros for other colors are just as easily done.  As a 
  277. reference, the ANSI codes for colors are:
  278.  
  279. 1 bold
  280. 4 underline
  281. 5 blink
  282. 7 reverse
  283. 30-37 foreground black/red/green/yellow/blue/magenta/cyan/white
  284. 40-47 background black/red/green/yellow/blue/magenta/cyan/white
  285.  
  286. <ESC>[1;34;42m is, thus, boldface blue on a green background (the 
  287. 1, 4 and 5 commands are toggles).
  288.  
  289. You can generalize the /blue macro by:
  290.  
  291. /def color = /gag %-1 = //echo -w %e[%1m%%*%e[0m
  292.  
  293. This would be used to simulate /blue by "/color 34 <text>".  For 
  294. boldface blue on a green background, "/color 1;34;42 <text>".
  295.  
  296.  
  297. OTHER IDEAS
  298. -----------
  299. The /pcmd macro (/def pcmd = /pfxon%;%*%;/pfxoff) doesn't allow you to
  300. execute multiple commands or use tf commands, because argument substitutions
  301. don't undergo newline substitutions.  However, you can use a more general
  302. version of /pcmd to get around this:
  303.  
  304.   /def pcmd = /def pcmdtmp = //pfxon%%;%*%%;//pfxoff%;/pcmdtmp%;/undef pcmdtmp
  305.  
  306. Now you can use /pcmd to, say, get to a certain room and then execute a macro
  307. called foo:
  308.  
  309.   /pcmd home%;step1%;step2%;/foo
  310.  
  311. Simple triggers, such as the ones in the autoreturn example, can be 
  312. used to gag any output between the prefix and suffixes, producing 
  313. silent movement.
  314.  
  315. Some useful tools:
  316.  
  317.      /def get = /grab //edit %1 = $%1
  318.      /def qline = /quote :quotes, "#"%{1}-%1""
  319.      /def qback = /quote :quotes, "#"-%1""
  320.      /def getline = /quote //grab #%{1}-%1
  321.  
  322.