Paying for randomly-selected decision within a randomly-selected app

213 views
Skip to first unread message

ryan rholes

unread,
Jan 7, 2022, 9:02:41 AM1/7/22
to oTree help & discussion
Hello, 

I am running an experiment that uses three apps. In each app, a subject will make two decisions. 

I would like to pay each subject for one of his/her choices from only one of these apps. I would like the software to choose both things at random (the app and, for that app, one of the two decisions). 

Is this possible? 


Cheers! 

Max R. P. Grossmann

unread,
Jan 7, 2022, 9:11:11 AM1/7/22
to ryan rholes, oTree help & discussion
Hi Ryan,

Have you considered saving the decisions that could be paid in participant.vars? Anything saved in participant.vars stays there for the entire session. At the end, you could randomly draw from there.

Best,

Max

ryan rholes

unread,
Jan 7, 2022, 11:28:45 AM1/7/22
to oTree help & discussion
Hi all, 

I tried following the solution that Chris provides on oTreehub, but am getting the following error: "AttributeError: 'Participant' object has no attribute 'app_payoffs'"
I use this code in Subsession: 
"
for p in subsession.get_players():
        # initialize an empty dict to store how much they made in each app
        p.participant.app_payoffs = {}

"

and this code in Group: 
"

import random

for p in group.get_players():
    participant = p.participant
    x = random.randint(100, 200)
   
    if x <=149:
        p.potential_payoff = p.earnings1 + p.range1_earnings
    else:
        p.potential_payoff = p.earnings2 + p.range2_earnings    
    # __name__ is a magic variable that contains the name of the current app
    participant.app_payoffs[__name__] = p.potential_payoff

"

then call the function in the waiting page at the end of the app. 

ryan rholes

unread,
Jan 13, 2022, 7:45:17 AM1/13/22
to oTree help & discussion
Just wanted to say that I have everything working thanks to your help. I appreciate it! 
Reply all
Reply to author
Forward
0 new messages