[Tutor] my newbie program
david
din22@cox.net
Tue Nov 26 23:37:01 2002
thanks for looking at my program. i will take
your advice to heart.
>
> >class Actor:
> > def __init__(self):
> > self.location=startroom
>
> Pass start room in as a parameter instead of using a global.
not sure what you mean here though.
> > def act(self):
> >
> > cmd = raw_input('>')
> > if len(string.split(cmd)) > 2:
> > print "too many words"
>
> >>> me.act()
> >dfg dfg dfg
> too many words
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "adventure.py", line 40, in act
> if verb == 'dig':
> UnboundLocalError: local variable 'verb' referenced before assignment
i saw this error and i don't know how to fix it. putting a break after the
print didnt work. i don't understand what a return statement would do.
> When you run into errors like this, a print isn't enough. You have
> to prevent further execution. I suggest that you put a return statement
> after the print. (Not only here I think.)
> Actor? Hm... Have you perchance been misled by the dark Sith
> Jacobson? He preaches that you should take the easy path and
> divide your classes into entities that contain data and controls
> (often actors) that do the work. Don't follow this path. It's
> the dark side of the force. (Sorry, I saw Star Wars II on video
> yesterday.) I'm still right though! ;) There might be a few cases
> where it's useful to have classes more specialized to handle data
> OR action, but in general it's something to avoid, and particularly
> for a beginner in object-oriented programming, it's important to
> try to get balanced classes. Seeing classes as either holders of
> data or holder of logic as above, will degenerate the code to bad,
> old structured code, and the benefits of OO is lost.
i see what you mean obiwan but i have never heard of jacobson.
i looked at some text adventure code that used actor and i just
borrowed the name.
> Magnus Lycka, Thinkware AB
> Alvans vag 99, SE-907 50 UMEA, SWEDEN
> phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
> http://www.thinkware.se/ mailto:magnus@thinkware.se
>