scripting_vars.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <html>
  2. <head>
  3. <link href="../tutorial.css" rel="stylesheet" type="text/css">
  4. </head>
  5. <body>
  6. <div class="header">
  7. The NakedMud Tutorial :: Scripting Variables
  8. </div>
  9. <!-- content starts here -->
  10. <div class="content-wrap"><div class="content-body-wrap"><div class="content">
  11. <div class="head">Scripting Variables</div>
  12. <div class="info">
  13. There are two main types of scripts in NakedMud. Prototypes generate content
  14. before it is added to the game. Triggers add behavior to rooms, objects, and
  15. mobiles when certain events happen. Other types of scripts can also exist. All
  16. scripts share a basic set of variables that reference relevant content to the
  17. script.
  18. </div>
  19. <div class="head" style="text-transform: none;">me</div>
  20. <div class="info">
  21. Almost all scripts are run on some piece of game content. Prototypes are run
  22. over blank objects, rooms, and mobiles to assign them values. Triggers are
  23. attached to these things, and run on them when certain in-game events occur. The
  24. thing a script is being run on is always referened by the 'me' variable.
  25. <p></p>
  26. Suppose you want to write a trigger that returns an object to its carrier's
  27. inventory whenever the object is dropped:
  28. <pre class="code">
  29. me.carrier = ch
  30. message(ch, me, None, None, True, "to_char",
  31. "As soon as you let go of $o, it flies right back into your hands!")
  32. message(ch, me, None, None, True, "to_room",
  33. "As soon as $n lets go of $o, it flies right back into $s hands!")
  34. </pre>
  35. </div>
  36. <div class="head" style="text-transform: none;">ch, obj, room, ex</div>
  37. <div class="info">
  38. Scripts will often involve more game contents than just the thing the script
  39. is being run on. Speech triggers involve the person hearing something, but they
  40. also involve a person saying something. The trigger is run on the person doing
  41. the hearing, which is referenced by me, so the person doing the speaking is
  42. referenced by ch:
  43. <pre class="code">
  44. if arg.lower() == "hello":
  45. me.act("delay 1 say hello to you too, " + ch.name + "!")
  46. </pre>
  47. Drop triggers can be attached to objects or rooms. What the trigger is attached
  48. to determines the value of me. A character always does the dropping, but cannot
  49. have a drop trigger attached to them. They are always referenced by ch. Consider
  50. this drop trigger that is intended to be attached to a room:
  51. <pre class="code">
  52. obj.carrier = ch
  53. message(ch, me, None, None, True, "to_char",
  54. "As soon as you let go of $o, it flies right back into your hands!")
  55. message(ch, me, None, None, True, "to_room",
  56. "As soon as $n lets go of $o, it flies right back into $s hands!")
  57. </pre>
  58. Note that this script is exactly the same as the earlier one, except that me
  59. has been replaced with obj. If a drop trigger with this script were attached to
  60. a room, it would return all dropped objects in that room to their owners' hands.
  61. <p></p>
  62. It is rarely (n)ever the case that a room is involved in a script where it is
  63. not the focus of that script. By and large, rooms are referred to as 'me'.
  64. However, it is feasible that such a situation could arise where two rooms are
  65. involved in the same script. For instance, a teleport script might move all
  66. things in one room to another one. In such a situation, the first room (the
  67. source) would be referred to as me. The second room (the destination) would
  68. be referred to as room.
  69. <p></p>
  70. Conversely, exits are almost never referred to as me. Remember, triggers can
  71. only be attached to rooms, objects, and mobiles. Also remember that prototypes
  72. only exist for those things too. If exits are involved in scripts they are only
  73. peripherally involved, and referenced by ex. Triggers that execute when a
  74. player enters or leaves a room will typically include an exit variable.
  75. </div>
  76. <div class="head" style="text-transform: none;">arg</div>
  77. <div class="info">
  78. Some scripts will also involve a string argument. This is referred to as arg.
  79. For instance, speech triggers will include the speech text. A room that
  80. transfered someone to another room when a magic word is said might have a
  81. trigger that looked like this:
  82. <pre class="code">
  83. if arg.lower() == "abra cadabra":
  84. ch.room = "newroom@nzone"
  85. ch.send("After you say the magic words, you find yourself somewhere else!")
  86. ch.act("look")
  87. </pre>
  88. </div>
  89. <!-- content ends here-->
  90. </div></div></div>
  91. <!-- navigation starts here -->
  92. <div class="nav-wrap"><div class="nav">
  93. <iframe src="nav.html" height="100%" width="100%" scrolling=no frameborder=0>
  94. </iframe>
  95. <!-- navigation ends here -->
  96. </div></div>
  97. <!--div class="footer">Edit Date: Nov 15, 2008. By Geoff Hollis</div-->
  98. </body>
  99. </html>