From 528ca6510a13d58b1a9fd1a8e82c2633ddd470b5 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 8 Aug 2020 18:24:29 +0200 Subject: Fixes issues with references handling. --- tonkadur_ui.py | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'tonkadur_ui.py') diff --git a/tonkadur_ui.py b/tonkadur_ui.py index 4ffaca4..5c1a6fa 100644 --- a/tonkadur_ui.py +++ b/tonkadur_ui.py @@ -1,3 +1,4 @@ +import sys import argparse import tonkadur @@ -19,30 +20,33 @@ parser.add_argument( args = parser.parse_args() state = tonkadur.Tonkadur(args.world_file) -#try: -while True: - result = state.run() - result_category = result['category'] - - if (result_category == "end"): - print("Program ended") - break - elif (result_category == "display"): - print(result['content']) - elif (result_category == "assert"): - print("Assert failed at line " + str(result['line']) + ":" + str(result['message'])) - elif (result_category == "resolve_choices"): - current_choice = 0; - - for choice in result['choices']: - print(str(current_choice) + ". " + ''.join(choice[0]['content'])) - current_choice += 1 - - user_choice = input("Your choice? ") - state.resolve_choice_to(result['choices'][int(user_choice)][1]) - elif (result_category == "event"): - print("Unhandled event:" + str(result)) - -#except Error: -# print("failed.\n") +try: + while True: + result = state.run() + result_category = result['category'] + + if (result_category == "end"): + print("Program ended") + break + elif (result_category == "display"): + print(result['content']) + elif (result_category == "assert"): + print("Assert failed at line " + str(result['line']) + ":" + str(result['message'])) + print(str(state.memory)) + elif (result_category == "resolve_choices"): + current_choice = 0; + + for choice in result['choices']: + print(str(current_choice) + ". " + ''.join(choice[0]['content'])) + current_choice += 1 + + user_choice = input("Your choice? ") + state.resolve_choice_to(result['choices'][int(user_choice)][1]) + elif (result_category == "event"): + print("Unhandled event:" + str(result)) + +except: + print("failed.\n") + print(str(state.memory)) + raise print(str(state.memory)) -- cgit v1.2.3-70-g09d2