Description of the problem:
I am coding a psychophysics experiment where at the beginning of each trial, a grey square is displayed on the screen. Under the grey square is a stimulus, but it is hidden from the subject. Over the course of the trial, the grey square becomes more transparent, slowly unveiling the stimulus drawn beneath at a constant rate. The goal for the subject is to press the space bar as soon as they can identify the stimulus that was previously hidden.
I am currently having trouble both simultaneously changing the opacity/transparency at a specified rate while recording a space bar press. Ideally, as soon as the subject makes a press, it will take them to a post-trial question. Any help about how to properly change opacity over time while recording a button press and moving to the next screen would be greatly appreciated! Below is the code I currently have, which is successful at changing opacity, but not recording a press and advancing.
timer.reset() while timer.getTime() < unveil_rate * 12: if timer.getTime() < unveil_rate: present_true_stimulus.draw() mask_stimulus.opacity = 1 mask_stimulus.draw() win.flip() elif timer.getTime() >= unveil_rate and timer.getTime() < unveil_rate * 2: present_true_stimulus.draw() mask_stimulus.opacity = .985 mask_stimulus.draw() win.flip() elif timer.getTime() >= unveil_rate * 2 and timer.getTime() < unveil_rate * 3: present_true_stimulus.draw() mask_stimulus.opacity = .970 mask_stimulus.draw() win.flip() elif timer.getTime() >= unveil_rate * 3 and timer.getTime() < unveil_rate * 4: present_true_stimulus.draw() mask_stimulus.opacity = .955 mask_stimulus.draw() win.flip() elif timer.getTime() >= unveil_rate * 4 and timer.getTime() < unveil_rate * 5: present_true_stimulus.draw() mask_stimulus.opacity = .940 mask_stimulus.draw() win.flip() elif timer.getTime() > unveil_rate * 5 and timer.getTime() < unveil_rate * 6: present_true_stimulus.draw() mask_stimulus.opacity = .925 mask_stimulus.draw() win.flip() elif timer.getTime() > unveil_rate * 6 and timer.getTime() < unveil_rate * 7: present_true_stimulus.draw() mask_stimulus.opacity = .910 mask_stimulus.draw() win.flip() elif timer.getTime() > unveil_rate * 7 and timer.getTime() < unveil_rate * 8: present_true_stimulus.draw() mask_stimulus.opacity = .895 mask_stimulus.draw() win.flip() elif timer.getTime() > unveil_rate * 8 and timer.getTime() > unveil_rate * 9: present_true_stimulus.draw() mask_stimulus.opacity = .88 mask_stimulus.draw() win.flip() elif timer.getTime() > unveil_rate * 9 and timer.getTime() < unveil_rate * 10: present_true_stimulus.draw() mask_stimulus.opacity = .865 mask_stimulus.draw() win.flip() elif timer.getTime() > unveil_rate * 10 and timer.getTime() < unveil_rate * 11: present_true_stimulus.draw() mask_stimulus.opacity = .850 mask_stimulus.draw() win.flip() elif timer.getTime() > unveil_rate * 12: present_true_stimulus.draw() mask_stimulus.opacity = .835 mask_stimulus.draw() win.flip() key = event.waitKeys() if key[0] in ['space']: break