WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-21-2011, 06:46 PM
vasiliys vasiliys is offline
Member
 
Join Date: Oct 2011
Posts: 3
Simplest script not working

I'm a bit dumbfounded by a tiny script not working the way I would expect:

This simple script should:
1. Turn the screen white on a 'w' press.
2. Turn the screen black on a 'b' press.
3. Turn the screen white, wait half a seconds and turn it black on a 's' press.

For some reason it will not turn it white on the 's' , though it does call the appropriate functions. I have no more ideas on what the issue could be. I hope someone here knows.

I have commented out all code irrelevant to the problem and it persists.

Code:
#import sys
import viz
#import vizparallel

viz.go()

def whiteScreen():
	print('White')
	viz.clearcolor(256, 256, 256)

vizact.onkeydown('w', whiteScreen)

def blackScreen():
	print('Black')
	viz.clearcolor(0, 0, 0)

vizact.onkeydown('b', blackScreen)

def sendSignal():
	whiteScreen()
	sendParallel()
	blackScreen()

vizact.onkeydown('s', sendSignal)

def sendParallel(signalCode = 24, delay = 0.5, port = 0x0378):
#	print('Sending code ' + str(signalCode) + ' for ' + str(delay) + ' seconds on port ' + str(port) + ' at tick ' + str(viz.tick()))
#	vizparallel.write( signalCode, port )
	sleep(delay)
#	print('Clearing with a zero at tick ' + str(viz.tick()))
#	vizparallel.write( 0, port )

def sleep(delay):
	start = viz.tick()
	while viz.tick() - start < delay: pass
	return viz.tick() - start
Reply With Quote
  #2  
Old 10-24-2011, 06:20 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,466
Try using a task function to control the program flow. In the following code the screen will turn white for 0.5 seconds after the 's' key is pressed:
Code:
import viz
import viztask

viz.go()

def whiteScreen():
	print('White')
	viz.clearcolor(256, 256, 256)

vizact.onkeydown('w', whiteScreen)

def blackScreen():
	print('Black')
	viz.clearcolor(0, 0, 0)

vizact.onkeydown('b', blackScreen)

def signalTask():
	while True:
		yield viztask.waitKeyDown('s')
		whiteScreen()
		yield viztask.waitTime(0.5)
		blackScreen()

viztask.schedule(signalTask())
Reply With Quote
  #3  
Old 10-25-2011, 10:24 AM
vasiliys vasiliys is offline
Member
 
Join Date: Oct 2011
Posts: 3
Quote:
Originally Posted by Jeff View Post
Try using a task function to control the program flow....
Thanks Jeff, I figured it out yesterday and made a solution similar to yours (though your method looks neater than mine so I will use it instead).

So from what I understand, though the clearcolor function was executing Vizard was only noting what color to change to. The color would actually change only once control flow was returned to Vizard - which is why it would appear as if only the final color was used.

Thanks for your help!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
starting Vizard from a Python script hotspur1 Vizard 12 06-12-2019 12:03 PM
Current working directory in Vizard Executable kevin Vizard 3 06-16-2011 11:31 AM
script file available - but missing spdegabrielle Vizard 1 05-06-2009 10:04 AM
Script loading problem JRichizzle Vizard 1 03-12-2004 10:03 AM
Working w/ multiple scripts FlyingWren Vizard 3 10-16-2003 01:05 PM


All times are GMT -7. The time now is 02:05 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC