I've been doing some more work on my robot today and I'm having a bit of trouble with calling a random function like so:
import speech import random import pythoncom running = 1 class OnTopic: topic = "nothing" def TopicChange(self): self.topic = "nothing" print OnTopic.topic class Know_Raptors: def RapYoung(self): speech.say("Did you know raptors took good care of their young") self.topic = "raptors young" def RapFeathers(self): speech.say("Did you know raptors probably had feathers") self.topic = "raptors feathers" AskRaptor = [ Know_Raptors().RapFeathers(), Know_Raptors().RapYoung() ] def command_callback(phrase, listener): if phrase == "tell me about raptors": #Here's where I'm stuck. random.choice(AskRaptor) if phrase == "yes": if self.topic == "raptors feathers": speech.say("Yes. Fossils indicate some of them had feathers") elif self.topic == "raptors young": speech.say("Yes. Even cold-blooded predators can have a warm heart") else: speech.say("Yes what?") listener1 = speech.listenfor(["tell me about raptors", "yes"], command_callback ) while running == 1: pythoncom.PumpWaitingMessages()
By the way, this is using Michael gundlach's speech module (which is fabulous!)
What I want it to do is when I ask "tell me about raptors," I want my robot to randomly chose one of the two functions in the class Know_Raptors. The problem is when I ask, "tell me about raptors," it registers the phrase but nothing happens.
And besides that, I notice that instead of waiting for me to say "tell me about raptors" my robot goes and says both the functions in order.
I'd make the first line in the function just a string and then put the "speech.say" in the command callback for AskRaptor, but then I still want to assign the value "raptors young" or "raptors feathers" to "self.topic."
I've tried all sorts of things in the script and in the command prompt, but to no avail. Anyone know what I should do?
Thanks in advance!