#1 by Becky
Hi,
I'm making a program and I can't figure out payoffs. They keep coming up as 0, so I know I haven't set the payoffs correctly, but I can't figure out what I'm doing wrong. If anyone could help me out, I would be super grateful. Thanks you! (code below)
from otree.api import *
import itertools
doc = """
This is my idea for a dice game
"""
class C(BaseConstants):
NAME_IN_URL = 'BeesDice_app'
PLAYERS_PER_GROUP = 3
NUM_ROUNDS = 2
payment_conversion = cu(10)
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
bus_name = models.StringField(label="Your Business name:")
fin_roll_one = models.CurrencyField(label='What is the value of the first dice?')
#fin_roll_two = models.IntegerField(label='What is the value of the second dice?')
#fin_roll_three = models.IntegerField(label='What is the value of the third dice?')
#fin_roll_four = models.IntegerField(label='What is the value of the fourth dice?')
#fin_roll_five = models.IntegerField(label='What is the value of the fifth dice?')
acct_roll_one = models.CurrencyField(label='What is the value of the first dice?')
#acct_roll_two = models.IntegerField(label='What is the value of the second dice?')
#acct_roll_three = models.IntegerField(label='What is the value of the third dice?')
#acct_roll_four = models.IntegerField(label='What is the value of the fourth dice?')
#acct_roll_five = models.IntegerField(label='What is the value of the fifth dice?')
earn = models.CurrencyField()
tax = models.CurrencyField()
net = models.CurrencyField()
# Functions:
def creating_session(subsession):
treatment = itertools.cycle([1, 2, 3])
for player in subsession.get_players():
participant = player.participant
participant.treatment = next(treatment)
def set_player_treatment(player):
if player.id_in_group == 1:
player.treatment = 'treatment_1'
elif player.id_in_group == 2:
player.treatment = 'treatment_2'
else:
player.treatment = 'treatment_3'
player.participant.vars['treatment'] = player.treatment
def get_treatment(player):
treatment = player.participant.vars.get('treatment')
return treatment
# PAGES
class Intro(Page):
form_model = 'Player'
form_fields = ['bus_name']
@staticmethod
def is_displayed(player):
return Player.round_number == 1
class Fin(Page):
# making it simpler to play through for testing
#form_model = 'player'
#form_fields = ['fin_roll_one', 'fin_roll_two', 'fin_roll_three', 'fin_roll_four', 'fin_roll_five']
form_model = 'player'
form_fields = ['fin_roll_one']
class EarlyWaitPage(WaitPage):
wait_for_all_groups = True
class Acct(Page):
# Making it simpler for testing
#form_model = 'player'
#form_fields = ['acct_roll_one', 'acct_roll_two', 'acct_roll_three', 'acct_roll_four', 'acct_roll_five']
form_model = 'player'
form_fields = ['acct_roll_one']
class Results(Page):
@staticmethod
def vars_for_template(player: Player):
#earn= (player.fin_roll_one + player.fin_roll_two + player.fin_roll_three + player.fin_roll_four + player.fin_roll_five),
#tax = ((player.acct_roll_one + player.acct_roll_two + player.acct_roll_three + player.acct_roll_four + player.acct_roll_five) * .25),
#net = int(earn[0]) - int(tax[0]),
earn = player.fin_roll_one,
tax = player.acct_roll_one * .25,
net = cu(earn[0]) - cu(tax[0])
return dict(
earn=cu(earn[0]),
tax=cu(tax[0]),
net=cu(net)
)
def set_payoffs(player):
player.payoff = player.net
class LateWaitPage(WaitPage):
after_all_players_arrive = set_payoffs
class EndResults(Page):
pass
page_sequence = [Intro, Fin, Acct, EarlyWaitPage, Results, EarlyWaitPage, EndResults]
#2 by Daniel_Frey
Your LateWaitPage is not in page_sequence, therefore set_payoffs is not run. Furthermore, after_all_players_arrive is a group method, here is an example on how to set the payoff for each group member: https://otree.readthedocs.io/en/latest/multiplayer/waitpages.html#after-all-players-arrive) Best, Daniel
#3 by Becky
Hi!
Thank you for the help! I thought I had reset everything after I broke it all, but missed the waitpage change (I've tried so many ways to try and get payoffs to work!). I thought I tried this set up before, but I must have had something wrong (because it was coming up as 0s).
It's still not right though, all the payoffs are coming up as player 2s payoffs. (so everyone will say they have the same payoff as 2, and 2 will be accurate). Do you by any chance have any suggestions for what I need to change to fix this?
Thank you again!
class LateWaitPage(WaitPage):
@staticmethod
def after_all_players_arrive(group: Group):
for p in group.get_players():
p.payoff = Player.net
#4 by Daniel_Frey
It looks like if you take Player.net, it takes the value of net from one Player instance instead of each player in the group.
try this:
class LateWaitPage(WaitPage):
@staticmethod
def after_all_players_arrive(group: Group):
for p in group.get_players():
p.payoff = p.net
#5 by Becky
It works, thank you. I had a mismatch of Player when defining net and player/p which was screwing it up before that made the p not work at first (which is why I went with Player). It works now, you are the best!