Hey everyone,
I’m attempting to code an experiment that asks participants to click target stimuli intermixed with distractors. The code has no problem determining whether it was a target or a distractor that has been clicked, but if the mouse click is held down for more than an instant, it will keep adding to the counter for that respective stimulus.
The following is from the “each frame” tab in the main trial routine, as there are many stimuli on the screen at a given time and the routine ends on a timer:
for clickable in active_targs:
if mouse.isPressedIn(clickable):
clicked_targs.append(clickable.name)
thisExp.addData("clicked_targs",clicked_targs)
nTargClicks = len(clicked_targs)
for clickable in active_dists:
if mouse.isPressedIn(clickable):
clicked_dists.append(clickable.name)
thisExp.addData("clicked_dists",clicked_dists)
nDistClicks = len(clicked_dists)
The issue seems to be that it checks if the mouse is pressed on each frame, and if it is, it adds to the counter; so, if the mouse is pressed for more than one frame, the counter continues incrementing, rather than registering it as only one click.
To give some additional info which may be helpful, the clickable stimuli are boxes. Each box is determined to be a target or a distractor based on its position and its contents, and is added to a target or a distractor master list. There are 860 boxes total, which appear across 14 screens (60 boxes on each screen). Depending on how many times the routine has looped, the active targets and distractors are pulled from master lists and represented in “active_targs” and “active_dists” respectfully.
Essentially, the fix I am looking for would only increment the counters when the mouse has been ‘unpressed,’ so that way it does not keep adding to the counter if the mouse is pressed for more than a single frame.
If anybody has any ideas or solutions, please let me know. Also, if there is more information you would like about the code or the experiment, do not hesitate to reach out.
Thank you.