dynamic_descs.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 :: Dynamic Descriptions
  8. </div>
  9. <!-- content starts here -->
  10. <div class="content-wrap"><div class="content-body-wrap"><div class="content">
  11. <div class="head">Dynamic descriptions</div>
  12. <div class="info">
  13. One of the most powerful building features in NakedMud is the ability to embed
  14. Python code within text. This applies to room, mobile, object, and exit
  15. descriptions. But potentially, code can be embedded into any piece of text a
  16. player reads, if the codebase is set up to allow for it. To embed a piece of
  17. Python code, it must simply be encased in a [ and a ]. The value of the code
  18. will be processed as the text is seen. Here is an example from a room that
  19. will display a character's race and gender back to them, as well as the room's
  20. name.
  21. <pre class="mud">
  22. ==========================================================================
  23. Begin editing. /q on a new line to quit, /a to abort. /h for help
  24. ==========================================================================
  25. ] <font class="cmd">Your name is [ch.name] and you are [ch.sex].</font>
  26. ] <font class="cmd">You are currently standing in [ch.room.name].</font>
  27. ]
  28. </pre>
  29. Here is what is seen when I look while standing in the room.
  30. <pre class="mud">
  31. > <font class="cmd">look</font>
  32. [example_room@tutorials] [Inside] An Example Room
  33. Your name is Alister and you are male. You are currently standing in An
  34. Example Room.
  35. </pre>
  36. Any piece of Python code that evaluates to a string or number can be embedded
  37. within a description. A list of useful functions and content properties that can
  38. be accessed with embedded code is covered in the scripting tutorial. You may
  39. have noticed that I make reference to the variable, 'ch'. This refers to the
  40. person performing the look command. And of course, ch.name refers to that
  41. person's name.
  42. <p></p>
  43. Embedded scripts have two important variables defined within
  44. them: ch and me. The first variable, ch, is the person doing the looking.
  45. me is the place or thing being looked at. Therefore, the exact same output
  46. could be obtained with the following embedded script:
  47. <pre class="mud">
  48. ==========================================================================
  49. Begin editing. /q on a new line to quit, /a to abort. /h for help
  50. ==========================================================================
  51. ] <font class="cmd">Your name is [ch.name] and you are [ch.sex].</font>
  52. ] <font class="cmd">You are currently standing in <font class="highlight">[me.name]</font>.</font>
  53. ]
  54. </pre>
  55. </div>
  56. <div class="head">Conditional descriptions</div>
  57. <div class="info">
  58. So far, we have discussed how to embed code within descriptions. However, we
  59. have only shown how to unconditionally display pieces of code. NakedMud also
  60. allows you to conditionally display information. To do this, you need to make
  61. use of [if], [elif], [else], and [/if]. Any text (or code) that appears between
  62. a conditional evaluation, [if], and its closing statement, [/if], will only be
  63. displayed if the evaluation is true. Here is an example of a room that will
  64. display back a character's name to males.
  65. <pre class="mud">
  66. ==========================================================================
  67. Begin editing. /q on a new line to quit, /a to abort. /h for help
  68. ==========================================================================
  69. ] <font class="cmd"><font class="highlight">[if ch.sex=="male"]</font>Your name is [ch.name].<font class="highlight">[/if]</font></font>
  70. ] <font class="cmd">You are currently standing in [me.name].</font>
  71. ]
  72. </pre>
  73. Conditionals can also have alternatives. For instance, you can display something
  74. different to men and women by providing an [else] before the [/if].
  75. <pre class="mud">
  76. ==========================================================================
  77. Begin editing. /q on a new line to quit, /a to abort. /h for help
  78. ==========================================================================
  79. ] <font class="cmd">[if ch.sex=="male"]Your name is [ch.name].</font>
  80. ] <font class="cmd"><font class="highlight">[else]Hey baby, what's your name?</font>[/if]</font>
  81. ] <font class="cmd">You are currently standing in [me.name].</font>
  82. ]
  83. </pre>
  84. Finally, you can have a list of conditionals evaluate in succession, with
  85. the first one that evaluates true being displayed. This is done with the
  86. [elif] option.
  87. <pre class="mud">
  88. ==========================================================================
  89. Begin editing. /q on a new line to quit, /a to abort. /h for help
  90. ==========================================================================
  91. ] <font class="cmd">[if ch.sex=="male"]Your name is [ch.name].</font>
  92. ] <font class="cmd"><font class="highlight">[elif ch.sex=="female"]</font>Hey baby, what's your name?</font>
  93. ] <font class="cmd">[else]What ARE You?[/if]</font>
  94. ] <font class="cmd">You are currently standing in [me.name].</font>
  95. ]
  96. </pre>
  97. </div>
  98. <div class="head">Applying dynamic descriptions</div>
  99. <div class="info">
  100. One application of dynamic descriptions is to provide different room
  101. descriptions depending on whether it is day or night. Or maybe you might
  102. make it so important information about the surroundings is only displayed if
  103. a player's perception is above a certain amount. Embedded code is extremely
  104. flexible, and the details of its use are limited only by your imagination (and
  105. ability to script). Here is a practical example of changing a city street's
  106. description, depending on the time of day.
  107. <pre class="mud">
  108. ==========================================================================
  109. Begin editing. /q on a new line to quit, /a to abort. /h for help
  110. ==========================================================================
  111. ] <font class="cmd">The street is nicely kept cobblestone. Buildings of various sizes dot the </font>
  112. ] <font class="cmd">north and south sides of the street. <font class="highlight">[if is_night()]</font> The doors and windows on</font>
  113. ] <font class="cmd">most are shut, suggesting the town has gone to bed for the night.<font class="highlight">[/if]</font></font>
  114. ] <font class="cmd"><font class="highlight">[if is_evening() or is_night()]</font> Flames flicker at the tops of tall polls </font>
  115. ] <font class="cmd">lining either side of the street. They give off basic illumination.<font class="highlight">[/if]</font></font>
  116. ]
  117. </pre>
  118. </div>
  119. <!-- content ends here-->
  120. </div></div></div>
  121. <!-- navigation starts here -->
  122. <div class="nav-wrap"><div class="nav">
  123. <iframe src="nav.html" height="100%" width="100%" scrolling=no frameborder=0>
  124. </iframe>
  125. <!-- navigation ends here -->
  126. </div></div>
  127. <!--div class="footer">Edit Date: Nov 15, 2008. By Geoff Hollis</div-->
  128. </body>
  129. </html>