| Reference | Downloads | Github

Problem with coding variated durations of stimuli

PsychoPy version : 3.2.4

Hi !

I am currently building an experiment during which a visual count down is presented to the participants. Previously to the visual count down, participants are rating the intensity perceived from a video on a visual analogue scale. I want this visual countdown to vary (i.e., 0,2,4,6,8,10,12,14,16,18, or 20) accordingly to the previous response of the participant on the intensity VAS, which can vary between 0 and 1. However, I can’t make it out.

I am using the Builder option and I’ve tried few things.

First, in the properties basic options for my visual countdown, I’ve added the variable $rating in the ‘Stop’ option with the ‘’Condition’’ option selected. Then, I’ve added a Loop for my trial with the following options: loopType=interleaved staircases, nReps=24, starType=simple and switchMethod=sequential. In the options ‘’Conditions’’, I’ve linked an Excel sheet which included the two colons (i.e. rating and time). All possible ratings options were added (i.e., 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, and 1.0) with the corresponding time (i.e., 0,2,4,6,8,10,12,14,16,18, or 20). The option ‘Is trials’ was checked.

However, I obtain the following error message:

line 292, in
AttributeError: ‘numpy.float64’ object has no attribute ‘reset’

I am not sure what to change to fixe it out.

Second, I’ve tried to add a code in ‘’Begin Routine’’ instead of a Loop, as follow:

if (rating= 0.0):
else(rating = 0.1):
else (rating = 0.2):
else (rating = 0.3):
else (rating  = 0.4):
else (rating = 0.5):
else (rating = 0.6):
else (rating = 0.7):
else (rating = 0.8):
else (rating = 0.9):
else (rating = 1.0):
    t=20    t=16
else (rating = 0.9):
else (rating = 1.0):

However, this led to the following error message:

line 276
if (ratingAide = 0.0):
SyntaxError: invalid syntax

As I am not used to code, I am not sure what is the error here and how to get it fix.

If someone as an idea of what causes the problem and potentials solutions, I would be very helpful and appreciated.

Thank you for your time! :slight_smile:

This isn’t valid Python if/then syntax. Firstly, try here for some pointers:

and note that in Python (like some but not all programming languages), you need to distinguish between = (making a value equal to another) and == (comparing two values for equality).

But then also be aware that you can’t (in any programming language) reliably test floating point numbers for equality to a point value, as, unlike integers, computers can’t represent floating point numbers with perfect precision.


>>> a = 1.2 - 1.0
>>> a == 0.2

The danger is that such comparisons do work often enough to lull you into a false sense of security, but rest assured, they will fail at some point.

So your tests have to be for a range of values, using > and <= etc rather than just ==