Commits

Anonymous committed 528f768

clean up char.act() and the assiciated doctests.

Comments (0)

Files changed (1)

rpg_lib/anyrpg.py

 	text_to_print = ""
 	# Preserve leading spaces. 
 	if text: 
-	    while text[0] == " ": 
+	    while text and text[0] == " ": 
 		text_to_print += " "
 		text = text[1:]
 	# Print as many words as possible without breaking the max line width. 
         """Say something -> Show that the char says it."""
 	if localize: 
 	    data = _(data)
-	# First we need an empty line, so the text is set off from the rest. 
+	# First we need an empty line and a line with the name, so the text is set off from the rest. 
 	self.diag(linesep + self.name, localize=False, autoscroll=autoscroll, *args, **kwds)
+	# Now we speak all lines but the last. 
         for i in data.splitlines()[:-1]: 
             self.split_diag(i, localize=False, autoscroll=autoscroll, line_beginning = ' ' * indent, *args, **kwds)
 	# Add the last line without autoscrolling to wait for the user to read the next part. 
 	# Then ask the last line
         return super(Char, self).ask(' ' * indent + data.splitlines()[-1], localize = False, *args, **kwds)
     
-    def act(self, data, *args, **kwds): 
+    def act(self, data, localize = True, autoscroll=True, *args, **kwds): 
         """Do something -> Show that the char does it in the style "<name> walks away.".
         
         Usage: 
             >>> char = Char(source="tag:1w6.org,2008:Mins")
             >>> char.act("walks away.")
-            \033[0GMins walks away.
+            \033[0G
+	    Mins walks away.
+	    >>> char.act('''keeps walking
+	    ... and walking
+	    ... and walking.''')
+            \033[0G
+	    Mins keeps walking
+	    \033[0G     and walking
+	    \033[0G     and walking.
         """
-        data = _(data)
-        for i in data.splitlines(): 
-            self.split_diag(self.name + ' ' + i, localize=False, *args, **kwds)
+	if localize: 
+	    data = _(data)
+	# First we need an empty line and a line with the name, so the text is set off from the rest. 
+	firstline = linesep + self.name + " " + data.splitlines()[0]
+	self.diag(firstline, localize=False, autoscroll=autoscroll, *args, **kwds)
+	# Now we add the rest, with an indentation equal to the length of the name. 
+        for i in data.splitlines()[1:]: 
+            self.split_diag(' '*(len(self.name)) + i, localize=False, *args, **kwds)
         
     def compete_skill(self, other, skill_name, self_mods=[], other_mods=[]): 
         """Compete with the other char in the specified skill.