WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 05-12-2014, 03:16 PM
bvldtiger bvldtiger is offline
Join Date: Mar 2014
Posts: 2
Scope of global variable limited to function

I have the following code:

def enterEnd(e):
end = time.clock()
position = viz.MainView.getPosition()
ZpositionEnd = position[2]
global elapsedTime
global deltaZpos
elapsedTime = end - start
deltaZpos = ZpositionEnd - ZpositionStart
print 'Final speed', deltaZpos/elapsedTime

This works with a sensor and provides head location data for a motion capture experiment. However, when I try to access the deltaZpos variable in another function I get the following error:

Traceback (most recent call last):
File "C:\Program Files (x86)\WorldViz\Vizard4\python\", line 779, in updateAndKillOnException
return self.update()
File "C:\Program Files (x86)\WorldViz\Vizard4\python\", line 749, in update
val = self._stack[-1].send(sendData)
File "C:\Users\jorge_leon\Jorge_VR\Fajen_Sequence_Offic", line 252, in experiment_Fajen
yield testPhase()
File "C:\Users\jorge_leon\Jorge_VR\Fajen_Sequence_Offic", line 235, in testPhase
speed = deltaZpos/elapsedTime
NameError: global name 'deltaZpos' is not defined

I checked and the scope limits itself to the function definition but I want to make sure that any other function can access it, and other variables in other functions do the same.
Reply With Quote
Old 05-13-2014, 04:32 PM
bvldtiger bvldtiger is offline
Join Date: Mar 2014
Posts: 2
The other function's code:

# Output all data to file here
def testPhase():
speed = deltaZpos/elapsedTime
Reply With Quote
Old 05-15-2014, 02:14 AM
Jeff Jeff is offline
WorldViz Team Member
Join Date: Aug 2008
Posts: 2,467
Is testPhase called before enterEnd? If so then the variables will not be defined and you'll get that error message.
Reply With Quote

time, vizard 4

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
return variable from keypress function starbug Vizard 2 01-07-2010 12:14 PM
how can I stop an action? nlfrnassimi Vizard 4 02-13-2009 01:59 AM

All times are GMT -7. The time now is 09:41 PM.

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