Iterating and indexing to produce feedback change in colour

I am working on a task where a participants use a net (which is dragged on screen by making it contingent with the mouse) to search for a hidden coin.

It is all functional but I’m looking to make the net change colour based upon the size of the error made by participants.

I am defining the error as the difference between the target’s actual position and the mouse position (x only) using code like this:

difference = target_coin.pos[trials.thisRepN] - mouse.getPos()[0]
if difference[trials.thisRepN] < 0.07:
    net_feedback.color = "green"
    net_feedback.color = "white"

But what it seems to be doing is turning green when it isn’t meant to (when the error made by the participant is very large). I think the issue I am having is specifying my target position on a specific trial. I thought the code for this was:


However, I think I need to refer to only the x co-ordinate. How would I do this? I tried matching this up to the heading I have for the coin position in the conditions file but it treats the positions as a float and not a list.

The value of .pos should be two numbers: x and y. So I would have thought indexing it using thisN would cause an error as soon as thisN exceeds 1?

.pos should return its position at the time when the code is called - so if you’re doing this via the Routine Start or Routine End tab of a code component it should give you the position at the start/end of each routine respectively.

Thank you for your help. I think I have solved this issue now- by thinking through the maths rather than the code.

I can use the name of the x position co ordinate from the conditions file and this did work. However I was calculating the error and using an inequality if statement (i.e. if error > 0.05 then change to green). As a result for the positive side of the screen (right) it was turning green no matter what.

So it was a case of making my sure I did the square root of my squared error to get a meaningful error/difference value.

1 Like