Putting a variable from code in a conditions file

TL;DR - I can’t find a way to make an image and a polygon scroll in tandem with one another by importing their variable positions from a conditions file.

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2.4
Standard Standalone? (y/n) If not then what?: Y
What are you trying to achieve?:
My ultimate goal is to have an image scroll like a website. Participants will be tasked with finding something on the image and clicking on it. To achieve this, I want a polygon shape to be behind the image in the right location of where the participant needs to click. Ultimately, I need the image to scroll like a webpage and I need the polygon to scroll in tandem with the webpage.

What did you try to make it work?:
I figured out how to make the image scroll using the following code set in the ‘every frame’ tab.

oldY = webpage.pos[1];
deltaY = (mouse.getWheelRel()[1] * .10);
newY = (oldY + deltaY);
webpage.pos = [0, newY];

I was able to make the polygon scroll correctly if I set the position for the polygon in the code as follows.

polygon.pos = [x, y+newY]
#the x and y values are actual numbers(float) in the code for an individual polygon

Problem is I need the polygon to be in a different position for each trial since the image will also be different.

What specifically went wrong when you tried that?:
I have a column in my conditions file that essentially does the polygon.pos code above but when I go to import the conditions file with the ‘newY’ in the polygon_position column, I get an error.

Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\builder\dialogs_init_.py”, line 1531, in onBrowseTrialsFile
_c, _n = data.importConditions(dlg.GetPath(),
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\utils.py”, line 339, in importConditions
trialList, fieldNames = _attemptImport(fileName=fileName,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\utils.py”, line 263, in _attemptImport
trialList, fieldNames = pandasToDictList(trialsArr)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\utils.py”, line 320, in pandasToDictList
val = eval(val)
File “”, line 1, in
NameError: name ‘newY’ is not defined

I’ve tried a ton of other things. I’ve created individual variables for the x and y coordinates in the code and tried to pull in the variables from the conditions file to include the newY in the code and that gives me a different error. When I do this, I set the polygon position in the properties to (0,0) since that’s how it’s set for my image and it works fine there.

newpx=polygonx
newpy=polygony
polygon.pos = [newpx,newpy+newY]
"C:\Users\NZXT\OneDrive\Documents\DeSart_518FinalProject\DeSart_518FinalProject_lastrun.py", line 379, in <module>
    win.flip()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\window.py", line 1082, in flip
    thisStim.draw()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\shape.py", line 275, in draw
    vertsPix = self.verticesPix
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py", line 779, in verticesPix
    self._updateVertices()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py", line 823, in _updateVertices
    verts = (verts.pix - self._pos.pix).dot(self._rotationMatrix) + self._pos.pix
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\layout.py", line 851, in pix
    return self.getas('pix')
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\layout.py", line 813, in getas
    verts += getattr(self.pos, units)
ValueError: operands could not be broadcast together with shapes (4,2) (2,1) (4,2) 

I would split polygon_position into two columns: polygon_x and polygon_y. Then you could set the position as $[polygon_x,newY+polygon_y] in your component.