![]() |
|
|
|
#1
|
|||
|
|||
|
Thank you, Frank, that works great!
|
|
#2
|
|||
|
|||
|
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()
|
|
#3
|
|||
|
|||
|
Hi Saajaja,
Seems like you already figured out how to solve your problem. However, a simpler solution seems like to yield a function, where you do something with the input. Everything that is in that function should be executed before showing the world again. Now, I just print the input and wait a few seconds, so you can see that everything in the function is executed before executing the rest of the code. Code:
import viz
import vizinput
import vizact
import viztask
piazza = viz.add('piazza.osgb')
viz.go()
def printValue(value):
print value
viz.waitTime(4)
def getInput():
# Blindfold.
viz.MainScene.visible(0,viz.WORLD)
viz.clearcolor(viz.SKYBLUE)
yield viztask.waitFrame(1)
# Ask for input
input = ''
while input == '':
input = vizinput.input('Input something.')
yield printValue(input)
# Unblindfold.
viz.MainScene.visible(1,viz.WORLD)
viz.clearcolor(viz.BLACK)
yield viztask.waitFrame(1)
def inputScreen():
viztask.schedule(getInput)
vizact.onkeydown(' ', inputScreen)
|
|
#4
|
|||
|
|||
|
That's much better! Thank you very much, Frank.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Screen Size and Scaling | javadi | Vizard | 2 | 04-02-2013 06:56 PM |
| Pygame Screen within Vizard World | VirtuallyInsane | Vizard | 4 | 02-18-2013 10:50 AM |
| Attach a TexQuad to pit.osgb screen | Ducky | Vizard | 1 | 01-17-2013 03:57 PM |
| split screen | honey006 | Vizard | 3 | 05-21-2009 10:57 AM |
| position of html-file on screen | active_world | Vizard | 1 | 05-16-2008 08:24 PM |