Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with classes
#8
I'll remember that the next time nilamo. Thanks.

So, I tried your suggestion, but I still got the same error:

Error:
Traceback (most recent call last):   File "ex43_mine.py", line 253, in <module>     a_game.play()   File "ex43_mine.py", line 44, in play     next_scene_name = current_scene.enter()   File "ex43_mine.py", line 66, in enter     loaded_alien = load_alien('central_corridor') NameError: global name 'load_alien' is not defined
My Aliens class now looks like this, with the rest the same as before:

class Alien(object):

    def __init__(self, alien_name, alien_lair):
        self.alien_name = alien_name
        self.alien_lair = alien_lair
        self.health = 2

        aliens = {
            'central_corridor': 'puppeteer',
            'laser_weapon_armory': 'kzin',
            'the_bridge': 'trooper',
            'escape_pod': 'predator',
        }

    # loads corresponding alien onto scene
    def load_alien(self, alien_lair):
        alien = self.aliens(alien_lair)
        return alien
Also, shouldn't get() be used to return the key value from the dict, which in this case is the alien itself? I'm using lines 230-232 as a point of reference here.

Cheers,
 
Reply


Messages In This Thread
Help with classes - by J125 - Dec-04-2016, 05:04 PM
RE: Help with classes - by ichabod801 - Dec-04-2016, 05:34 PM
RE: Help with classes - by J125 - Dec-06-2016, 02:33 PM
RE: Help with classes - by nilamo - Dec-06-2016, 04:00 PM
RE: Help with classes - by J125 - Dec-07-2016, 10:15 PM
RE: Help with classes - by J125 - Dec-14-2016, 06:36 PM
RE: Help with classes - by nilamo - Dec-14-2016, 06:58 PM
RE: Help with classes - by J125 - Dec-15-2016, 03:27 AM
RE: Help with classes - by Larz60+ - Dec-15-2016, 06:33 AM
RE: Help with classes - by J125 - Dec-15-2016, 03:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using classes? Can I just use classes to structure code? muteboy 5 5,200 Nov-01-2017, 04:20 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020