rabdill / bishops_map_legacy

A data-driven text adventure engine written in Python. (No longer active; being ported to Javascript.)
0 stars 0 forks source link

Entering a non-integer quantity at a store exits the store #20

Open rabdill opened 9 years ago

rabdill commented 9 years ago

If setting the qty as an integer fails, it just turns it into a zero: ''' if command < len(current['items']): choice = get_text("How many? (You have {0} coins, or enough for as many as {1}) > ".format(player['inventory']['coins'], player['inventory']['coins']/current['items'][command]['price'] ), debug, player) try: qty = int(choice) except ValueError: #if it's not an integer qty = 0 #skips all the checking and asks for another response '''

rabdill commented 9 years ago

The solution is to replace the "get_text" function used here with a new "get_int" function that asks for a new entry when it doesn't get a number. Can be used, here AND in selecting the item you want to buy in the store.