From 43aad028d75c7bbc27938bff1aea371b5c6bf781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Wed, 3 Nov 2021 10:16:56 +0100 Subject: [PATCH] Selections should work --- loader.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/loader.py b/loader.py index 01ba816..85bff09 100644 --- a/loader.py +++ b/loader.py @@ -11,10 +11,12 @@ class Game: self.nodes.update({k:game[k]}) def make_selection(self,selection): - if(selection >= len(self.nodes[self.current][selection]) or selection < 0): + if(selection is not int or selection >= len(self.nodes[self.current][selection]) or selection < 0): print("Invalid selection") + return False else: self.current = self.nodes[self.current][selection] + return True def printme(self): @@ -28,6 +30,12 @@ class Game: ostring+=f"{i} - {self.nodes[option]['description']}\n" print(ostring) sel = input("Make a selection (number): ") + isWrong = self.make_selection(sel) + while isWrong == False: + sel = input("Make a selection (number): ") + isWrong = self.make_selection(sel) + self.printme() + def load(file_path): '''Loads the game from a YAML file to a Game class'''