View Single Post
Old 12-17-2007, 10:31 AM
Karla Karla is offline
Join Date: May 2007
Posts: 12
Turning info boxes on and off

Below is the code from my .py file.

I would like to program info boxes to appear and disappear based on user input or a timer, not from clicking on the logo to shrink the box. For example, a box with 3 choices appears to collect the user's choice of phrase. It disappears after the user clicks OK. Then an info box appears to tell the user the avatar's reply. After 2 seconds (enough time to read the reply), that info box disappears. Then another box with 3 choices appears to collect the user's next choice of phrase, and so on. I'm having a problem with the timing.

After running the file, if you press '5' an info box will appear. Once you click the OK button, the first info box will disappear, but a second info box does not appear as it should. Line 74 should make this box appear; line 77 should wait 2 seconds; and line 78 should make this box disappear.

Any advice is greatly appreciated!


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
# Make an action when a key is pressed.
def mykey(key):
	global subTalk, OKbutton, aRadio, bRadio, cRadio, charTalk
	if key == ' ':    			#if the pressed key is space bar
		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
	#Show a Transparent Message Box 
	if key == '5': #if the pressed key is '5'
		subTalk = vizinfo.add("")		#Add the vizinfo object
		subTalk.translate(1.0,.95) 		#Set position on screen
		subTalk.title("Chat Box") 		#Give it a title.
		subTalk.visible(viz.ON)  		#Display the Message Box
		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
		print aRadio.get()

# Make an action when a BUTTON is pressed.
def onButton (button,state):
	global subtalk, OKbutton, aRadio, bRadio, cRadio, charTalk
	if button == OKbutton and state == viz.DOWN:
		aans = aRadio.get()
		bans = bRadio.get()
		cans = cRadio.get()		
		viztask.waitTime(1) 		#Wait 1 second
		subTalk.visible(viz.OFF)  #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.
		charTalk.visible(viz.ON)  		#Display the Message Box
		print aans
		viztask.waitTime(2) 			#Wait 2 seconds to read avatar's response
		charTalk.visible(viz.OFF)  		#Remove the Message Box
		print bans
		print "place holder"
viz.callback(viz.BUTTON_EVENT, onButton)

def mytimer(num):

#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