I want to randomize the number of repeats($nReps) in ‘trials’ loop
I have to create an experiment in which we make 12 blocks of random trials.
In each trials, when ‘space’ pressed, the image feedback appears and
when the trials are repeated for the number between 5 and 16 times,
the chocolate feedback appears.
Each block contains randomized number of trials(5-16 times).
What specifically went wrong when you tried that?:
when I put the code at ‘Begin Experiment’
it worked, but at ‘Begin Routine’, it didn’t work with no error output.
My problem is that If I put it at ‘Begin Experiment’,
the number of repeats is same for each of 12 blocks.
Code that runs at the beginning of a routine is inside the loop, so it is too late to affect the creation of the loop, which has already occurred. So what you should do is:
run that code at the start of the experiment (as you have done above), so that a value for the variable will be available for the very first run of the loop.
in the “begin routine” tab, you’ll probably want to save the chosen value in the data, e.g:
thisExp.addData('repeats', repeats)
On the last iteration of the trials loop, you’ll need to update the value of nrepeats for the next time it runs. So put something like this in the “end routine” tab:
if trials.nRemaining == 0:
nrepeats = numpy.random.randint(5,16)
NB the second parameter in the call to randint is exclusive, so it will return values ranging from 5 to 15.
I could give not only the immediate feedback for responses, but also the “reward feedback” which is given for several button presses.
But, there are two problems. First, I would like to put intertrial interval for about 20 seconds after “reward feedback”, but in my routine, the [space] key response also works intactly in intertrial interval which is time for pause.
Second, I would like to put black background, using polygon rectangle, but, it’s not possible to make the polygon appear behind the other stimulus.
The drawing order of components is from top (first) to bottom (last). So if you want the black rectangle stimulus to appear in the background, move it to the top (by right-clicking on its icon).
I haven’t looked at your file, and am not entirely sure I understand the issue, but don’t forget that you can split your trial into multiple consecutive routines. e.g. allow the space key to end the first routine, and then immediately present a second routine for the inter-trial interval. This second routine would be set to have a fixed duration of 20 seconds and to not respond to key presses.