python - Class keeps repeating itself, despite having a 'return' statement for the next class -


this first attempt @ learning programming language... ok, i'm working on exercise 45 of learn python hard way, trying create text-based game. i've had few roadblocks far, 1 far frustrating. have borrowed (and tweaked) author's code previous exercise, allowed use of 1 function, enter(), per class, want use five. this, tried implement try/exception tree run additional functions if there, , if not, move on next classs.

what happens is, first class, introscreen(), runs fine, points bedroom() fine, , bedroom repeats on , on again, though have command return kitchen(), next class.

i have added #comment# in code below show think it's messing up. if know how fix this, please help; or, better, if have better way of doing fantastic. i've been told looks kinda screwy.

i can provide entire code if helps; please, me out!

   class map(scene):       scenes = {         'introscreen': introscreen(),         'bedroom': bedroom(),         'kitchen': kitchen(),         'fourth': fourth()         }      def __init__(self, start_scene):         self.start_scene = start_scene      def next_scene(self, scene_name):         return map.scenes.get(scene_name)      def opening_scene(self):         # think part that's screwing up!!!         return self.next_scene(self.start_scene)  class engine(object):      def __init__(self, scene_map):         self.scene_map = scene_map      def play(self):         current_scene = self.scene_map.opening_scene()          while true:             print "----------"             try:                 next_scene_name = current_scene.enter()              except:                  try:                     next_scene_no2 = current_scene.second()                  except:                      try:                         next_scene_no3 = current_scene.third()                      except:                          try:                              next_scene_no4 = current_scene.fourth()                          except:                              try:                                     next_scene_no5 = current_scene.fifth()                              except:                                 break              current_scene = self.scene_map.next_scene(next_scene_name)      

in map class, wanting create new instance of map?

def next_scene(self, scene_name):     return map.scenes.get(scene_name)  <----  def opening_scene(self):     # think part that's screwing up!!!     return self.next_scene(self.start_scene) 

when debugging, use print statements easy way see happening, e.g.

def next_scene(self, scene_name):     tmp_scene = map.scenes.get(scene_name)     print('in map:next_scene - tmp_scene = ', tmp_scene)     return tmp_scene 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -