Anonymous committed aa93640

begun writing an exlicit answer passing system. Todo: integrate in char.ask and integrate improvements in char.ask into ask().

Comments (0)

Files changed (2)


         super(UserInteraction, self).__init__(*args, **kwds)
-    def ask(self, question=None, localize = True, end_with_linebreak = True, *args, **kwds): 
+    def ask(self, question=None, answers = [], default_answer = 0, localize = True, end_with_linebreak = True, capital_default = True, *args, **kwds): 
         """Ask a question.
         Note: Not console based implementations will want to overwrite this. 
-		- ask(question=None, default=0, *answers, **kwds) - usage: ask("why", "because", "it's how it is", "I don't know", default=2) -> default capitalized, rest small print. 
+		- ask(question=None, default=0, *answers, **kwds) - usage: ask("why?", "because", "it's how it is", "I don't know", default=2) -> default capitalized, rest small print. 
         if question is not None: 
+	    # Optionally localizing everything. 
 	    if localize: 
-		answer = raw_input(_(question) + " ")
-	    else: 
-		answer = raw_input(question + " ")
+		question = _(question)
+		if answers: 
+		    answers = [_(answer) for answer in answers]
+	    # capitalize the default answer, except if the user says otherwise. 
+	    if capital_default and answers: 
+		answers = [answer.lower() for answer in answers]
+		answers[default_answer] = answers[default_answer].capitalize()
+	    if answers: 
+		question += " ( " + ", ".join(answers) + " )"
+	    answer = raw_input(question + " ")
 	    if end_with_linebreak: 
 		# Add an empty line with autoscrolling to show that we're now at the next part. the user already provided input, so we don't need to ask for input again. 


 ### Lines needed in EVERY simple rpg scripting module (changing their effect for all places where they get used can only be done in the Story class) ###
-def ask(question, *args, **kwds): 
+def ask(question, answers=[], default_answer=0, *args, **kwds): 
     """Ask a question. 
     @return: The answer of the user."""
-    return story_helper.ask(question, *args, **kwds)
+    return story_helper.ask(question, answers=answers, default_answer=default_answer, *args, **kwds)
 def diag(text, localize=True, autoscroll=False, *args, **kwds): 
     """Output some text.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.