PDA

View Full Version : DeprecationWarning when running a yield statement


armo
08-18-2014, 12:56 PM
Hello

I am working on this script where I run a task, wait for the user to give a mouse response and store the reaction time. Below is the task:

def example_trial():
response = viz.Data()
startTime = viz.tick()
yield viztask.waitMouseDown( None, response )
print 'response at: ', viz.tick()
reactionTime = response.time - startTime
print reactionTime


but when it comes to the yield line it gives me this warning, and I can't figure out what it means and how to fix it

DeprecationWarning: "data" option will be removed in future versions, use "[data] = yield [condition]" instead
yield viztask.waitMouseDown( None, response )

P.S. I have run the same code with a previous Vizard version and then I didn't get the warning

Jeff
08-18-2014, 02:58 PM
The viztask.waitMouseDown command has been updated and no longer expects the viz.Data object to be passed as an argument. Use the following instead:

def example_trial():
startTime = viz.tick()
response = yield viztask.waitMouseDown( None )
print 'response at: ', viz.tick()
reactionTime = response.time - startTime
print reactionTime

farshizzo
08-19-2014, 11:23 AM
To be clear, this is just a warning. Your existing code should still function properly. Deprecated functions are not removed until the next major version, so you have until Vizard 6 to update your code.

If you would like to simply disable the warnings, then add the following code to the beginning of your script. However, I would strongly recommend that you just update your code.
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

armo
08-20-2014, 05:41 AM
Dear all

Thanks for the reply. There is no problem for me about updating my code but I would ask you if I can still use the "response.time" variable as it was written in the snippet above in order to calculate user's reaction time and the "response.button" in the snippet below to obtain the mouse button:

if response.button == viz.MOUSEBUTTON_LEFT:
outResponse = "left response"
elif response.button == viz.MOUSEBUTTON_RIGHT:
outResponse = "right response"


regards, armo

Jeff
08-20-2014, 10:35 AM
Yes, the data object returned by viztask.waitMouseDown (http://docs.worldviz.com/vizard5/#commands/viztask/waitMouseDown.htm) still contains that information.