AttributeError: 'tuple' object has no attribute 'enter'

Help! I’m coding a game program for my daughter and I come up with the following error:
Traceback (most recent call last):
File “/home/roberto-padilla/mystuff/ella_game.py”, line 193, in
a_game.play()
File “/home/roberto-padilla/mystuff/ella_game.py”, line 22, in play
next_scene_name = current_scene.enter()
^^^^^^^^^^^^^^^^^^^
AttributeError: ‘tuple’ object has no attribute ‘enter’

Here’s the code:

class Engine(object):

    def __init__(self, scene_map):
        self.scene_map = scene_map
    
    def play(self):
        current_scene = self.scene_map.opening_scene()
        last_scene = self.scene_map.next_scene('finished')

        while current_scene != last_scene:
            next_scene_name = current_scene.enter()
            current_scene = self.scene_map.next_scene(next_scene_name)

        current_scene.enter()
class Map(object):
    scenes = {
        'outside_house': OutsideHouse(),
        'kitchen': Kitchen(),
        'foyer': Foyer(),
        'living_room': LivingRoom(),
        'dark_woods': DarkWoods(),
        'cellar': Cellar(),
        'witch_house': WitchHouse(),
        'death': Death(),
        'finished': Finished(),
    }

    def __init__(self, start_scene):
        self.start_scene = start_scene

    def next_scene(self, scene_name):
        val = Map.scenes.get(scene_name)
        return val
    
    def opening_scene(self):
        have_bone = False
        return self.next_scene(self.start_scene), have_bone

a_map = Map('outside_house')
a_game = Engine (a_map)
a_game.play()

Any help would be greatly taken and appreciated. Thanks in advance for your help!

It’s complaining about this line:

next_scene_name = current_scene.enter()

Where does the value of current_scene come from?

It comes from this line:

current_scene = self.scene_map.opening_scene()

What does self.scene_map.opening_scene() return?

It returns a tuple (a pair of values) self.next_scene(self.start_scene), have_bone.

Tuples don’t have a method called enter, hence the error.

1 Like

I would add to @MRAB 's answer, which is correct, that it appears the root cause is
opening_scene should return self.next_scene(self.start_scene) not a tuple with have_bone because it needs to return the same as next_scene for the while loop to work.