text_editing.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 :: Text Editing
  8. </div>
  9. <!-- content starts here -->
  10. <div class="content-wrap"><div class="content-body-wrap"><div class="content">
  11. <div class="head">Text Editing</div>
  12. <div class="info">
  13. NakedMud has a simple, built-in text and script editor. This can be useful for
  14. writing and editing game content. The OLC system and helpfiles make copious
  15. use of the editor. The editor can be accessed via Python as well as C. This
  16. tutorial explains how to use it via Python to edit a player's description.
  17. </div>
  18. <div class="head">Describing Yourself</div>
  19. <div class="info">
  20. Sockets can enter text editor mode with the edit_text method. This method takes
  21. three arguments. The first is a string, setting the initial content of the text
  22. editor. The second is a function, called after the text editor is quit. This
  23. will be used to read the output of the text editor, and allow you to save it
  24. somewhere. The third is optional; you can specify whether you want to enter
  25. "text" or "script" mode. This will change syntax highlighting and formatting
  26. rules for the editor, as appropriate for either pure-text or python script
  27. editing.
  28. <p></p>
  29. Here are a set of functions that allow a player to change his or her own
  30. description:
  31. <pre class="code">
  32. import mudsys # needed for add_cmd
  33. def finish_desc_editor(sock, editor_output):
  34. '''this function is passed to edit_text, and called after a socket exits the
  35. text editor.'''
  36. # make sure our character has not somehow vanished.
  37. # If it is still around, change its description to the output of the editor
  38. if sock.ch != None:
  39. sock.ch.desc = editor_output
  40. def cmd_describe(ch, cmd, arg):
  41. '''Allows a character to set his or her own description.'''
  42. # first, make sure we have a socket. The text editor pushes an input
  43. # handler onto the socket's stack. Thus, the socket needs to exist.
  44. if ch.sock != None:
  45. ch.send("You seem to be missing a socket.")
  46. else:
  47. # edit text editor mode. Set the initial value of the text editor to
  48. # our current description. When the text editor is finished, call the
  49. # function we're passing in
  50. ch.sock.edit_text(ch.desc, finish_desc_editor)
  51. # add the 'describe' command to the game
  52. mudsys.add_cmd("describe", None, cmd_describe, "player", True)
  53. </pre>
  54. </div>
  55. <div class="head">Script Editing</div>
  56. <div class="info">
  57. NakedMud also has an Python mode for the text editor. This is what is used for
  58. writing triggers and the 'extra code' section of game content. If you instead
  59. wante to edit script editor mode, specify this as a third argument to edit_text:
  60. <pre class="code">
  61. sock.edit_text(initial_value, finish_function, "script")
  62. </pre>
  63. </div>
  64. <!-- content ends here-->
  65. </div></div></div>
  66. <!-- navigation starts here -->
  67. <div class="nav-wrap"><div class="nav">
  68. <iframe src="nav.html" height="100%" width="100%" scrolling=no frameborder=0>
  69. </iframe>
  70. <!-- navigation ends here -->
  71. </div></div>
  72. <!--div class="footer">Edit Date: Nov 15, 2008. By Geoff Hollis</div-->
  73. </body>
  74. </html>