Presenting a random number as positive or negative feedback for a response

OS (e.g. Win10): OSX Sierra 10.12.5
PsychoPy version (e.g. 1.84.x): 1.85.2
Standard Standalone? (y/n) If not then what?:y
What are you trying to achieve?:
I am trying to code a simple reward task in which participants make a binary choice (e.g., guess high or low) about the value of a stimulus, and experience monetary gain or loss as a positive or negative outcome if they were ‘correct’ or 'incorrect. In reality there is no correct answer; reinforcement is fixed so all participants will receive a positive outcome on 50% of trials and a negative outcome on 50% of trials. On a given trial, if a participant makes a choice and it is scheduled to be a positive outcome, after making their guess, they will see a random number corresponding to their choice––e.g., guessing ‘high’ will result in the presentation of a ‘high’ number (e.g., random number between 6 and 9). If it is scheduled to be a negative outcome, if they guess high, they will see a random number corresponding to the opposite of their choice (e.g., random number between 1 and 4).

What did you try to make it work?:
I have set up the experiment file via the builder such that there are 2 main routines, a positive outcome routine and a negative outcome routine, each with a response object that can accept 2 possible responses (e.g., ‘1’, ‘2’) but not designating either of them as correct. Instead, I have inserted a code object into each routine. In the ‘begin experiment’ field, I have input the following:

outcome = []

and in the ‘begin routine’ field, I have the following code:

if response.keys == 1:
    outcome = random.randint(1,4)
elif response.keys == 2:
    outcome = random.randint(5,9)
elif not response.keys:
    outcome = "No Response"

And in the text object that is supposed to display the outcome to them, I have insert a variable $outcome in the text field.

What specifically went wrong when you tried that?:
Upon running this, after making a response on the first trial, the experiment displays [] for the outcome instead of an actual number based on my response, and on subsequent trials, regardless of whether I make a response, the outcome displayed on the screen is ‘No Response’.

Any suggestions as to how I should effectively code what I am trying to do would be much appreciated.

Thanks in advance,
Dominic

Hi Dominic, you have put your code in the begin routine tab. This means that it will be executed before the keyboard object has had a chance to get a response. Hence outcome keeps its default value of [] on the first trial, and it will be "No response" on subsequent trials, but that value will have actually carried over from the previous trial (if the text stimulus is above the code component in your routine window: swap the order if you want the text stimulus to get the current value).

This code needs to go elsewhere, so that it runs after a response has been made. The way it has currently been written means that it would have to go in the End routine tab, but it is also possible to monitor responses on every screen refresh. Perhaps the easiest thing would be to split your routines in two, so that the text display occurs in a separate routine that is only displayed once the response has been made on the previous routine.

Hi Michael,

Thanks for your response. I took your suggestions and was able to get it to work as I wanted it to.

Best,
Dominic

1 Like