@wakecarter suggests using something called string concatenation to construct the image filename. In string concatenation you combine several strings to form a larger string. If the string concatenation results in a wrong name, PsychoPy wonât find the file.
Looking at your problem, the first part of your string is âreward/Candyâ, the second part is the sum of the variable candies + 1 and the last part is â.pngâ. You need str(candies + 1) to convert the sum of the integer variable candies + 1 into a string. So you need to construct the string concatenation so that it produces the string results you want! And details matter!
If your intended string is âreward/Candy1.pngâ, where the number is the variable part, you need to construct the string in the following way, as already mentioned
Note the order of the arguments and the extra 1 in the second command. You print candieImage to the console to see if you construct the proper image filename.
Hii,
Thanks for explaining the issue so nicely. And I would like to apologize for such long delay in response, since I got busy with other stuffs and could not work on this experiment. I understood the part about string concatenation and how that will produce the name of the image expected to be called. However, I still have some issues in the experiment.
About the image calling part, I wanted to call the image only after 10th, 20th, 30th trial and so on, and not after every trial. Currently the image is being called after every trial.
About the calculation of accuracy, I wanted to exclude only the first trial, which is happening. The accuracy value should remain the same on an incorrect trial, and should increment on the next correct trial. What is happening is, on an incorrect trial, the accuracy value is incremented and it remains the same on the next trial even if that trial is correct.
I have attached an excel sheet which explains the desired accuracy and reward (candies) value and the actual values that are coming.
At the moment you are setting skipReward = True in Begin Experiment but you arenât resetting it to True after itâs False. Add an else condition or reset it in Begin Routine or End Routine before your if clause.
I added respMade clause because the experiment was treating missed trials (trials with no response made) as correct only and incrementing the accuracy in that case as well.
With this code now, the reward image is being displayed only after there is an increment in the candy value. If there is no increment in the candy value (i.e. the accuracy<6), there is no reward image (the previous reward image should repeat itself in this case, i.e., if it is one candy image previously, it should repeat that image). Also, along with this, the code is skipping the part where accuracy should be set to 0 after the 10th trial and start recounting from the 10th trial.
In target routine, where I take the responses on the target and response images are being displayed, I used respMade because if there is a no response on the first trial, there was some error coming up.
So below is the code which I put there to avoid this error and it worked there,
Begin Routine
This is the intended behaviour according to the tab alignments in your code. Please have a go at editing it so that only lines you what to execute when accuracy reaches 6 are tabbed to be executed in this if clause. Remove tabs from the others so they are executed every 10 trials regardless.
I wonder if clauses of the form
RW_color1_image_PPC.image == RW_CorrAnsPPC_T might not be working as intended. Personally I would put that kind of code in End Routine but I donât think thatâs the issue. Try printing you values for correct to the console.
I tried to do what you suggested here, and it seems that worked. Although, the reward image in this case is displayed after 11th trial is completed (which should be displayed after the 10th trial). Another thing is that if the reward image is to be repeated (i.e., the candy value remains the; accuracy<6), the reward image does not display.
print('RW_PPC.thisN', RW_PPC.thisN,'respMade', respMade, 'candies', candies, 'accuracy', accuracy, 'correct', correct, )
if RW_PPC.thisN >= 0 and respMade == 1 and correct:
accuracy += 1
if RW_PPC.thisN in [10, 20, 30, 40, 50, 60, 70, 80]:
if accuracy >= 6:
candies += 1
skipReward = False
accuracy = 0
candieImage = "reward/Candy" + str(candies) + ".png"
print('candieImage', candieImage)
else:
skipReward = True
When the candies value remained the same, there was no display of the reward image. As you will observe, even if the response was not made, it took it as correct, and still incremented the accuracy value. Same thing happened if there was an incorrect response.
Also, from the 11th, 21st, and so on trials, the accuracy value is always 0 irrespective of whether the trial was correct or not.