From b6108592b66cc14573e5614aa5c878b71c6be6cb Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sun, 30 Aug 2020 02:14:07 +0200 Subject: Changes how choices are handled. --- tonkadur.py | 15 +++++++++++---- tonkadur_ui.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tonkadur.py b/tonkadur.py index 0bfe8d6..61e87a8 100644 --- a/tonkadur.py +++ b/tonkadur.py @@ -32,6 +32,7 @@ class Tonkadur: self.code = [] self.program_counter = 0 self.allocated_data = 0 + self.last_choice_index = -1 self.available_choices = [] with open(json_file, 'r') as f: @@ -199,10 +200,14 @@ class Tonkadur: # if (isinstance(target, list)): # print("That's a list.") return target + elif (computation_category == "last_choice_index"): + return self.last_choice_index + else: + print("Unknown Wyrd computation: \"" + computation_category + "\"") - def resolve_choice_to (self, line): + def resolve_choice_to (self, index): self.available_choices = [] - self.program_counter = line + self.last_choice_index = index def run (self): while True: @@ -215,8 +220,7 @@ class Tonkadur: if (instruction_category == "add_choice"): self.available_choices.append( [ - self.compute(instruction['label']), - self.compute(instruction['address']) + self.compute(instruction['label']) ] ) self.program_counter += 1 @@ -275,6 +279,7 @@ class Tonkadur: result = dict() result["category"] = "resolve_choices" result["choices"] = self.available_choices + self.program_counter += 1 return result elif (instruction_category == "set_pc"): @@ -303,4 +308,6 @@ class Tonkadur: pre_val[last_access] = result self.program_counter += 1 + else: + print("Unknown Wyrd instruction: \"" + instruction_category + "\"") diff --git a/tonkadur_ui.py b/tonkadur_ui.py index de1001e..85f91e4 100644 --- a/tonkadur_ui.py +++ b/tonkadur_ui.py @@ -57,7 +57,7 @@ try: current_choice += 1 user_choice = input("Your choice? ") - state.resolve_choice_to(result['choices'][int(user_choice)][1]) + state.resolve_choice_to(int(user_choice)) elif (result_category == "event"): print("Unhandled event:" + str(result)) -- cgit v1.2.3-70-g09d2