#1
|
|||
|
|||
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) |
Thread Tools | |
Display Modes | Rate This Thread |
|
|