1. Arne Babenhauserheide
  2. TextRPG

Commits

Arne Babenhauserheide  committed aa93640

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

  • Participants
  • Parent commits d187cdf
  • Branches default

Comments (0)

Files changed (2)

File rpg_lib/anyrpg.py

View file
  • Ignore whitespace
         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. 
 	
 	Plans: 
-		- 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: 
 	    sleep(0.01)
+	    # 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. 

File rpg_lib/textrpg.py

View file
  • Ignore whitespace
 
 ### 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.