View Single Post
  #4  
Old 11-13-2013, 09:31 PM
saajaja saajaja is offline
Member
 
Join Date: Nov 2011
Posts: 14
Dear Frank,

I spoke too soon. Your code helped speed me in the right direction, but it had a semantic bug. Execution would continue before the actual input value was received. So if we wanted to actually do anything with the input string, we would end up doing weird stuff that we didn't want to do.

In order to make the program wait for an actual input to arrive from the user, I did some fancy signal stuff based on your code and the two balls example at the bottom of Task Basics.

Code:
import viz
import vizinput
import viztask

class test:
	def __init__(self):
		piazza = viz.add('piazza.osgb')
		
		self.input = 'initialized value'
		vizact.onkeydown(' ', self.getAndPrintInput)
		self.gotInputSignal = viztask.Signal()
		
		viz.go()

	def getInput(self):
		# Blindfold.
		viz.fogcolor(viz.GRAY)
		viz.fog(.2)
		yield viztask.waitFrame(1)
		
		# Ask for input
		self.input = vizinput.input('Input something.')
		self.gotInputSignal.send()
		
		# Unblindfold.
		viz.fog(0)
		yield viztask.waitFrame(1)
	
	def printInput(self):
		# Wait for an actual input to arrive.
		yield self.gotInputSignal.wait()
		print self.input
	
	def getAndPrintInput(self):
		viztask.schedule( self.getInput() )
		viztask.schedule( self.printInput() )

t = test()
I learned a lot today. Thank you for your support!
Reply With Quote