aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-08-30 02:14:07 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-08-30 02:14:07 +0200
commitb6108592b66cc14573e5614aa5c878b71c6be6cb (patch)
treee6c262127a79f8142b9e0ebd443ab0af398b0aa8
parent1609330b4e4a1ad1e3ed26db75efdab5f9729663 (diff)
downloadtonkadur-python-interpreter-b6108592b66cc14573e5614aa5c878b71c6be6cb.zip
tonkadur-python-interpreter-b6108592b66cc14573e5614aa5c878b71c6be6cb.tar.bz2
Changes how choices are handled.
-rw-r--r--tonkadur.py15
-rw-r--r--tonkadur_ui.py2
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))