WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Saving/Loading data (https://forum.worldviz.com/showthread.php?t=1721)

TrashcanPatrol 11-18-2008 01:11 PM

Saving/Loading data
 
Hi, I've been wondering what is possible with Vizard to do in the case of saving and loading data?
I've found a post here that shows how to output the keystrokes to a text file, but I'm trying to save things such as what options were selected at a text box, if the player has already "talked" to an avatar, etc.
What are the options for this?

Jeff 11-19-2008 11:24 AM

Here's a link to a tutorial on creating data files. If you have further questions on writing your data to file let me know.

http://www.worldviz.com/vizhelp/Creating_data_files.htm

TrashcanPatrol 12-02-2008 03:23 PM

The code is not working for me... I keep getting this error from it:
Quote:

Traceback (most recent call last):
File "", line 11, in ?
File "quest.py", line 85, in ?
score_data = open('quest_data','a')
TypeError: 'VizText' object is not callable

farshizzo 12-02-2008 03:59 PM

This means you have assigned a text object to a variable named open, which conflicts with the built-in Python function. You should rename your text objects to something less generic.

TrashcanPatrol 12-04-2008 01:20 PM

The tutorial mentioned above uses the same code and it works, though...

Code:

import viz

import time

viz.go()

subject = viz.input('What is the participant number?')
viz.add('duck.cfg').translate(0,0,4)
critical_question = viz.add(viz.TEXT3D,'Do you see a duck?',viz.SCREEN)

yes = viz.add(viz.TEXT3D, 'Yes!',viz.SCREEN)
no = viz.add(viz.TEXT3D, 'No!',viz.SCREEN)

critical_question.alignment(viz.TEXT_CENTER_TOP)
critical_question.translate(.5,.9)

yes.alignment(viz.TEXT_LEFT_TOP)
yes.translate(.25,.75)

no.alignment(viz.TEXT_LEFT_TOP)
no.translate(.75,.75)

yes_button = viz.add(viz.BUTTON)
yes_button.translate(.22,.71)

no_button = viz.add(viz.BUTTON)
no_button.translate(.72,.71)

start_time = time.time()
question_data = open('duck_data','a')
def onbutton(obj,state):
    #Use our starting time variable to find out how much
    #time has elapsed.
    elapsed_time = time.time() - start_time
    #Create string lines to put in the data file, depending on which
    #button was pushed.
    if obj == yes_button:
        data = 'Subject ' + str(subject) + ' saw a duck.'
    if obj == no_button:
        data = 'Subject ' + str(subject) + ' did not see a duck.'
    #Write the data to our file.
    question_data.write(data)
    #Flush the internal buffer.
    question_data.flush()
    #Close the world.
    viz.quit()

viz.callback(viz.BUTTON_EVENT,onbutton)

In this, the file they're trying to open is duck_data; my file is called score_data, is that too generic?

Jeff 12-05-2008 04:02 PM

the problem is not the name of your file, score_data. Somewhere else in your script you have a variable named open. You'll just need to give that a new name

TrashcanPatrol 12-09-2008 03:04 PM

Ah yes, I looked around for 'open' and it seems I had forgotten that I had a text object outside of the script so it was on the stage. No wonder I was having so much trouble finding it... thanks for the help!

billjarrold 06-20-2012 10:29 AM

thanks - saved me time
 
thanks for making this post. it saved me a lot of debugging time!


All times are GMT -7. The time now is 08:53 PM.

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