| Reference | Downloads | Github

Unable to add ‘variable’ in a condition file


OS: MacOS Mojave (10.14.3)
PsychoPy 1.90.2
Standalone ver.

In the task, there is a stimulus in the background which is viewed through a moving slit.


This slit is made with two rectangles moving a set speed by updating its location ‘set every frame’ by time ’t’ (t is an internal time variable generated by psychopy?).

The slit should also move in every other direction (left to right, right to left, top to bottom, bottom to top and diagonally as well). As of now, I have made each direction into a separate routine.

I am trying to counterbalance the appearance of the routines (different slits directions) and the such as that order of routines/direction are not always the same.


  1. Randomize the routines:
    From what I have read this is not possible with coder/builder.? Or at least is not the suggested method.
    2)Update location from a condition file with location parameters for the rectangles such that I have a single routine.


When I try to load the condition file, I get an error - t is not defined.

I have also tried with other variables, for example, using Push in the location formula within the condition file and setting in the coder (Push = t) at ‘begin experiment’, ‘routine’ and ‘frame’ sections. It doesn’t work.

Please help.

Exp File:

@dev, the problem is you are using variables within your conditions file that are being evaluated when you load the conditions file. So, you are doing 0+Push*2, and these trial entries are being evaluated within the actual PsychoPy program, where those variables do not exist, rather than your experiment. To fix, you will need to remove the variables involved in mathematical operations. As your position operations are the same on each trial, just put them in the shape components position directly. So, PolyFronts position should be [0+Push*2,0].

Thank you for reply.
I uploaded a simple version of my paradigm.

Yes, that is how I have been doing it and thus have multiple routines (each describing the slit directions)…i.e. a total of 8 routines.

This doesn’t allow me to randomise the routine. eg.
Routine 1 - Slit moves left to right
Routine 2 - Slit moves top to bottom
Routine 3 - Slit moves diagonal (bottom left to top right)
Routine 4 - slit moves right to left.

What I would like is a single routine to go through different slit motions (RoutineAll - Cond1 Left to Right, Cond2 - Top to bottom etc. set in the conditions file.

or have the routines randomised (R1, R3,R4,R2; R1,R4,R3,R2 etc.)

any suggestions to how I can achieve this ?

Thank you.

Ok I can only see what you have shown me in your conditions file, but regarding your positions, everything is the same except the starting point on the x-axis, but you may also see changes in your y-axis as well. So, what I would do is use the conditions file to store only the numbers that change, i.e., the starting points (the Push variable is reset by t at the start of every routine). So, in your positions parameters in your shape component, you would have [xStart + Push * 2, yStart], but specific to each shape, so [FlocXStart + Push * 2, FlocYStart ]. In your conditions file, have columns for xStart and yStart for each shape, as in the attached.Cond1New.xlsx (8.6 KB). This way, randomisation is handled by the trial handler, and you only need 1 routine.

@dvbridges Thank you. I will give it a try.

@dvbridges Hi,

I tried implementing what you suggested and it has partially worked.

However, I get a following error - Unsupported value “0.0” for operation when setting pos in Rect

I am guessing this is because of some rounding issue and that RECT cant accept decimals ?

I tried using in the coder (begin routine)
import numpy as np and using FLoc = np.around (location formula) to get it to a single number, but it doesn’t work. Perhaps I am using it incorrectly?

This is how my location fields look like

The formula is now more complex but it should allow me (hopefully) to get all my directions in one routine.

Here is the latest condition file and exp.

Any suggestions?
Thank you for your help so far.
It has proved to be a great learning experience.

I think the error is because the Pos expects a tuple or list of values. Try surrounding your positions in square brackets and see if this fixes the error: e.g., [(FPosX+(t/tf)*TimeF)*PFHoldX,(FPosY+(t/tf)*TimeF)*PFHoldY]

@dvbridges Thank you!. It worked :slight_smile:

1 Like