psychopy.org | Reference | Downloads | Github

Record total money won

Hello everyone,

I’ve created a task where people can win 20p on certain trials if they respond quickly enough. I’m trying to sum the total money won as the task goes along.

This is what I’ve done so far -

Begin routine:

money_won_this_trial = 0
total_money = 0

End routine:

if target_resp_M.keys == 'space':
    if Feedback=='20p.jpg':
        money_won_this_trial=money_won_this_trial + 0.20
else:
    money_won_this_trial=0

total_money=money_won_this_trial + total_money
thisExp.addData('total_money', total_money)

total_money in the output is successfully showing money_won_this_trial, but it doesn’t record the total money won as the task goes along which is what I want.

Any help anyone could offer on this would be greatly appreciated! Thank you very much!

Hi @rachel.rodrigues, do you mean that total money is not written to the file, or that your total_money does not increase with every win? If the latter, it is because you are resetting the total_money variable back to zero at the beginning of every routine. You could move total_money to the “Begin Experiment” tab, so that it is set to zero only once per task, and then it increments by 20p with each win

Hi @dvbridges, just to let you know this is now working after moving total_money to begin experiment. Thank you very much!!

1 Like