#1 by cswell
Hello all, I'm still new to oTree (and programming in general). I'm trying to set payoffs for a Dictator game, where the Dictator will have 10 sets of choices and one will be chosen at random. I have set these choices up as integer field. So for example: class Player(BasePlayer): d5 = models.IntegerField( choices=[ [1, 'Do nothing'], [2, 'Give $5'], ], label = 'Choice #1:', widget=widgets.RadioSelect ) So d5 is just one set of choices the player can make.(d1-d10) My goal is to choose one of these payoffs at random, and then set payoffs for both players based on the choice made. I have thought about choosing a random integer to represent each set. Based on the random integer drawn, to look at the choice that the dictator makes for the associated decision set. So I am imagining this will be a large "if loop". However, I'm not sure where to set the payoff (in the player class?, etc.) And how to call the integer field result to set the payoff if it is possible. Any help that can serve as a starting off point would be helpful. Thanks.
#2 by cswell
Hello I'm adding this as an update I have coded the following loop to set my payoffs: class Player(BasePlayer): d5 = models.IntegerField( choices=[ [1, 'Do nothing'], [2, 'Give $5'], ], label = 'Choice #1:', widget=widgets.RadioSelect ) def set_payoffs(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) if group.pchoice == 1 and p1.d5 == 1: p1.payoff = 20 p2.payoff = random.randint(18,22) else: p1.payoff = 15 p2.payoff = random.randint(23,27) Where the variable pchoice: class Group(BaseGroup): pchoice = random.randint(1, 10) When I run oTree, I get payoffs of 0 in my results page, so I am a little confused as to what I am doing wrong. I have made sure to put "after_all_players_arrive = set_payoffs" in my "results waiting page" class.