WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-23-2007, 02:17 AM
jaclyn.bill jaclyn.bill is offline
Member
 
Join Date: Oct 2007
Posts: 42
text output

Dear all,

I'm using the script below in order to move a ball around the screen and save data to two text files. The first records keyboard and time responses, the second records x,y,z of the ball across time.

Whilst the keyboard responses are recording to text fine and the x,y,z data is visible in the output screen of vizard, only the last x,y,z co-ord is saving to the text file. Is there a simple command I'm missing, or is the issue because I'm trying to write two files at once?

I would be grateful for some help on this.

Thank you.

Jac

Code:
####code for recording the data.
def RecordTimer(pos, currentTime):
	file = open ('time.txt','w')
	currentTime = viz.tick()
	pos = gball.getPosition()
	save = '%d %.4f %.4f %.4f'%(currentTime * 1000,pos[0],pos[1],pos[2])###original
	file.write(save)
	file.flush()
	print save

def RunSimulation():
	
	#Repeat simulation indefinitely
	while True:
		
		#Wait for left mouse button to be pressed
		yield viztask.waitMouseDown(viz.MOUSEBUTTON_LEFT)
		
		#Place ball in starting position
		gball.add(motionseq)
		
		#Start timer to record ball position
		recordTimer = vizact.onupdate(0,RecordTimer)
		
		#Wait for ball to finish move action
		yield viztask.runAction(gball.add(motionseq))
		
		#Stop timer
		vizact.removeEvent(recordTimer)
	
viztask.schedule(RunSimulation())


import vizinfo

# Opens file 'response.txt' in write mode
file = open('response.txt', 'w')
   
# Define a function that saves data
def SaveData(currenttime, key):
    out = str(currenttime) + '\t' + key + '\n'
    file.write(out)
    file.flush()
    print out
   
# Define a function that is called every time a keyboard button is pressed
def mykeyboard(key):          
    # Calls the function SaveData and hands it the current time and key
    SaveData(viz.tick(),key)

# Defines a callback for keyboard events
viz.callback(viz.KEYBOARD_EVENT, mykeyboard)
Reply With Quote
 


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


All times are GMT -7. The time now is 04:50 AM.


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