Actually, it was always converted to a numpy array. What’s new I think is that numpy now complains if you do the comparison np.array([1,2,3]) == [1,2,3]
on the basis that the answer is ambiguous. In some worlds you might consider the answer to be True if any of the elements match. Personally I think that would be weird but strictly it’s true and that’s what numpy decided. So yes we now have to do something like convert to list first or use numpy.any()
I did still have that statement there, but for some reason it was still reading as a string. I’ve managed to sort that out in the meantime, so the clicks will correctly register as ‘in list’ and ‘not in list’. However, they still won’t change colour (which also means the click count won’t work).
So far, I’ve only tried forcing the array back into a list, as you suggested above. I’m either not doing it correctly, or it just isn’t working for me. I’ve done some reading about numpy.any() and I’m unsure about how to implement it for this scenario, but perhaps it’s worth a shot? Would you mind briefly explaining how to approach that? Sorry again for all the issues - it ended up being a much bigger problem than I imagined.
for stimulus in allcircles:
if unaidedresponses.isPressedIn(stimulus):
if list(stimulus.fillColor) == [1.,1.,1.]:
ClickCount = ClickCount + 1
if stimulus in target_list:
stimulus.fillColor == (0,128,0)
print ("in list")
else:
stimulus.fillColor == (255,0,0)
print("not in list")
Thanks for the explanation as well @jon, much appreciated.
Those two things are mutually contradictory: if your code gets to the point where it is printing out “in list” or “not in list”, then it must have also incremented the click count? You could check by e.g. print(str(ClickCount1) + ' in list')
But if those messages are indeed being printed out, then the fill colour must be being set in code. The question then is whether there is a conflict with the Builder settings. Check your circle components. Are their colour fields set to update “every repeat” (they should be, to get re-set at the start of every trial). If they are set to “each frame”, then that could conflict with your code (i.e. it might override your code changes and reset the colour on every frame).
Sorry - I meant the click count still does not work as I intended (not that it doesn’t work at all).
For anyone looking for a solution to a similar problem, I later worked out that the issue was coming from importing the target list via a .csv/excel file, rather than from the code itself. Even after using the eval(targets) function as recommended above (and a bunch of other methods that I found on Stack Overflow/through other searches), it was still reading the targets as a string rather than a list.
To get around this, I ended up creating a list of targets for each trial in the ‘Begin Routine’ tab. I had six trials in this section, so created six target lists.
For example:
targetlist1 = [circle16, circle48, circle1, circle23, circle56]
targetlist2 == [circle47]
and so on.
For some reason, that made all the difference. I then used the same code that I was working on above::
if unaidedresponses.isPressedIn(stimulus):
if list(stimulus.fillColor) == [1.,1.,1.]:
ClickCount = ClickCount + 1
#print(type(stimulus))
if stimulus in targetlist1:
stimulus.fillColor = (0,128,0)
else:
stimulus.fillColor = (255,0,0)
if ClickCount == len(targetlist1) and not trial_ending:
trial_end_time = t + 0.5
trial_ending = True
if trial_ending and t >= trial_end_time:
continueRoutine = False
I then just looped through it for all the trials, and it worked perfectly. Thanks Michael for all your guidance and for answering all my questions - I definitely wouldn’t have landed on a solution without your help!