from otree.api import * doc = """ Trust Game Tutorial Pt. 3 """ #is this neccesary? # CLASSES class C(BaseConstants): NAME_IN_URL = 'trust_game' PLAYERS_PER_GROUP = 2 #are the names of these constants built in or not? NUM_ROUNDS = 1 ENDOWMENT = cu(10) MULTI_FACTOR = 3 INSTRUCTIONS_TEMPLATE = 'trust_game/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): #add range of options? sent_amount = models.CurrencyField( min=cu(0), max=C.ENDOWMENT, label="How much would you like to send to Participant B?" ) sent_back_amount = models.CurrencyField(label="How much would you like to send back?") class Player(BasePlayer): pass #FUNCTIONS def sent_back_amount_choices(group): #why do they do group: Group in example? return currency_range(0, group.sent_amount*C.MULTI_FACTOR,1) #why is there a 1 at the end of the range? def set_payoffs(group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff = C.ENDOWMENT - group.sent_amount + group.sent_back_amount p2.payoff = group.sent_amount * C.MULTI_FACTOR - group.sent_back_amount #PAGES class Send(Page): form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player): return player.id_in_group == 1 class WaitForP1(WaitPage): pass class SendBack(Page): form_model = 'group' #what do form_model and form_fields do? form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player): return player.id_in_group == 2 @staticmethod def vars_for_template(player): group = player.group return dict(tripled_amount=group.sent_amount * C.MULTI_FACTOR, sent_amount=group.sent_amount) #how do dictionaries work? class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): pass page_sequence = [ Send, WaitForP1, SendBack, ResultsWaitPage, Results, ]