Hello again, everyone.

My program for my robot is progressing. Thanks to your help its coming along great. I've also found that I'm more and more able to solve my own problems with programming now.

One thing that I can't seem to solve:

I'm working on a part of my robot's human-socialization program in which she keeps track of the topic, and then adds her own input. For example, if I talk to my robot about Disneyland, she'll keep track of different aspects of the theme park. I do this with a variable, say for each park, and if one of the varibles is greater than 3, she'll say something like, "You seem to like Main Street a great deal." That part works more or less fine.

But when I first start up the program and mention a ride at Disneyland, such as "Rail Road" I get this exception:

<type'exceptions.AttributeError'>:'MyApp' object has no attribute 'topic' at line 1.

This is the code associated with the recognized speech "Rail Road":

if self.topic == "disneyland":
	speaker.Speak(random.choice(DisneyRideTrain))
else:
	speaker.Speak('Cool. What rail road did you ride')

I know what the exception means: it means that unless I say change the topic to "disneyland" this snippet won't work because the variable "self.topic" doesn't have anything associated with it. So what I need is a default, or startup, value for "self.topic."

As simple as it sounds, I don't know how that would work. I've tried adding code like:

self.topic = "nothing"
print self.topic

under the class "MySpeechParser," which holds "self.topic"

But when I run the program, nothing seems to change. Even if I write the same code outside the MySpechParser class.

Anyone have any ideas? Thanks!

The normal way to handle this is in the init function inside class MyApp, you would write self.topic=None or something similar.

Ugh (head bonk) of course! That's why is says "MyApp" in there.

Okay, I added it under MyApp. It took a little while to debug a few things along the way, but it works great now!

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.