WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Writing data more than once (https://forum.worldviz.com/showthread.php?t=1767)

TrashcanPatrol 12-23-2008 03:58 PM

Writing data more than once
 
Hi, I tried a script to write data to a file outside of Vizard.

Code:

import viz
viz.go()

room=viz.add('room.wrl')
viz.collision(viz.ON)
import vizcam
vizcam.FlyNavigate()
subject = viz.input('Who are you?')

scoreLabel.score = 0
RECT3_X = -2
RECT3_Z = -2
RECT3_WIDTH = 0.5
Readboard = False
#score_data = open('quest_data','a','U')
def handlemyhotspots(id,x,y,z):
        global Readboard

        if id == BOARD:
                Readboard = True
                print 'Board has been read. +1'
                data = 'Mr. ' + str(subject) + ' was given 1 point for reading the instructions. '
        score_data.write(data)
        score_data.flush()
viz.starthotspot(BOARD,viz.RECTANGLE_HOTSPOT_IN,RECT3_X,RECT3_Z,RECT3_WIDTH,1)

That's part of the code. I'm trying to add another portion where if the player selects an object, data is written to the file score_data to say "Mr. ____ selected Item."
I can't seem to combine the two, or even get the second part of it to work by itself. Can anyone help me fix the problem?

Jeff 12-26-2008 01:24 PM

In this code the hotspot is triggered and data is written to the file. When you click on the ball, that data is also witten to the file. Is this helpful?

Code:

import viz
viz.go()

room=viz.add('court.ive')
ball = viz.add('ball.wrl', pos = [0,1,5])

subject = viz.input('Who are you?')

#open file to append to
score_data = open('quest_data.txt','a')

#write to file when hotspot triggered
def onHotspot(id,x,y,z):
       
        print "in hot spot"
        data = 'Mr. ' + str(subject) + ' entered the hotspot.' + '\n'
        score_data.write(data)

#Callback the hotspot event.
viz.callback(viz.HOTSPOT_EVENT,onHotspot)

viz.starthotspot(1,viz.RECTANGLE_HOTSPOT_IN,0,0,.5,.5)


#write to file when object is picked
def ballPicked():
        print "ball picked"
        score_data.write('Mr. ' + str(subject) + ' picked the ball.' + '\n')

vizact.onpick(ball, ballPicked)


#close the file when program is ended
vizact.onexit(score_data.close)


TrashcanPatrol 01-06-2009 03:56 PM

Ah yes! It works now! Thank you very much for your help :)


All times are GMT -7. The time now is 06:31 AM.

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