View Single Post
Old 12-17-2007, 02:08 PM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
You are using the viztask module incorrectly. You need to create a function that uses the yield statement and schedule it using the viztask.schedule command. I modified your example to use the viztask module. Let me know if anything is unclear:
import viz

import vizinfo	#For message box
import viztask 	#For wait time


male = viz.add('male.cfg')	#Add an avatar
male.state(1)				#Start in neutral state animation

face2 = male.face('biohead_talk.vzf')	#add a face to the avatar

smile = vizact.morph(0,2,0.5)		#Smiling face of male avatar
open = vizact.morph(5,0.5,0.5)	#mouth open morph of male avatar

def AvatarSmile():
	face2.add(smile) 		#Smiling face of male avatar
	face2.add(open) 		#Open mouth face of male avatar
	male.state(5)   		#Wave animation of male avatar
vizact.onkeydown(' ',AvatarSmile)

def StartQuestion():
	while True:
		yield viztask.waitKeyDown('5') #Wait for '5' key to be pressed
		subTalk = vizinfo.add("")		#Add the vizinfo object
		subTalk.translate(1.0,.95) 		#Set position on screen
		subTalk.title("Chat Box") 		#Give it a title.
		aRadio = subTalk.add(viz.RADIO, 0, "Hello.")	#Create a Radio button
		bRadio = subTalk.add(viz.RADIO, 0, "What is your street address?")
		cRadio = subTalk.add(viz.RADIO, 0, "What is your pet's name?")
		astext = "Hello."
		bstext = "What is your street address?"
		cstext = "What is your pet's name?"
		OKbutton = subTalk.add(viz.BUTTON, "OK")		#Create a button
		yield viztask.waitButtonDown(OKbutton) #wait for OK button to be pressed
		aans = aRadio.get()
		bans = bRadio.get()
		cans = cRadio.get()		
		yield viztask.waitTime(1) 		#Wait 1 second
		subTalk.remove()  #Remove the Message Box
		if aans == 1: 
			charTalk = vizinfo.add("It's nice to meet you.")
			print "A."
		elif bans == 1: 
			charTalk = vizinfo.add("Uh, that's personal. I'm Alex. Who are you?")
			print "B."
		elif cans == 1: 
			charTalk = vizinfo.add("Uh, that's personal. I'm Alex. Who are you?")
			print "C."   
			print "none"
		charTalk.translate(1.0,.95) 	#Set position on screen
		charTalk.title("Chat Box") 		#Give it a title.
		yield viztask.waitTime(2)		#Wait 2 seconds to read avatar's response
		charTalk.remove()  				#Remove the Message Box
#Schedule task that will ask user a question when '5' key is pressed and display a response
viztask.schedule( StartQuestion() )

#Adding a world
room = viz.add('panorama.ive')
room.scale(1,1,1)  		# scale actual
room.translate(0,0,0) 	# position in the world
Reply With Quote