oTree Forum >

Yes/No button functionality not working

#1 by pyth_123

Hi everyone i am building a simple trust game where in the start page if the participant selects no it will go directly to the thank you page. 

Can someone help me with the yes/No button functionality?

init function:

from otree.api import *

doc = """
Simple trust game
"""


class C(BaseConstants):
    NAME_IN_URL = 'trust_simple'
    PLAYERS_PER_GROUP = 2
    NUM_ROUNDS = 2
    MULTIPLIER = 3
    ENDOWMENT = cu(10)


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    sent_amount = models.CurrencyField(
        min=cu(0),
        max=C.ENDOWMENT,
        doc="""Amount sent by P1""",
        label="How much do you want to send to participant B?",
    )
    sent_back_amount = models.CurrencyField(
        doc="""Amount sent back by P2""",
        label="How much do you want to send back?"
    )


class Player(BasePlayer):
    name = models.StringField(label='What is your name')
    age = models.IntegerField(label='What is your age?', min=18, max=80)
    gender = models.IntegerField(choices=[
        [1, 'male'],
        [2, 'female'],
        [3, 'other']
    ]
    )
    grade = models.StringField(
        label='Please rate our experiment with the following numerical scale. 1 being the worst and 5 being the best',
        widget=widgets.RadioSelectHorizontal, choices=[1, 2, 3, 4, 5])
    education = models.IntegerField(
        choices=[[1, 'Less than a high school diploma/A-levels'], [2, 'High school diploma/A-levels'],
                 [3, 'Attended college/university'], [4, 'Undergraduate degree (BA/BSc/other)'],
                 [5, 'Graduate degree (MA/MSc/MPhil/other)'], [6, 'Doctorate degree (PhD/other)']],
        label='What is the highest level of education you completed?',
        widget=widgets.RadioSelect,
    )
    start_game = models.BooleanField()
    combined_payoff = models.CurrencyField()

# FUNCTIONS
def sent_back_amount_choices(group: Group):
    return currency_range(0, group.sent_amount * C.MULTIPLIER, 1)


def set_payoffs(group: 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.MULTIPLIER - group.sent_back_amount


# PAGES

class Start(Page):
    form_model = 'player'
    form_fields = ['start_game']

@staticmethod
def app_after_this_page(player, upcoming_apps):
    if player.start_game == 'No':
        return upcoming_apps[0]


class instructions(Page):
    pass


class Questions(Page):
    form_model = 'player'
    form_fields = ['age', 'gender', 'name']


class Send(Page):
    form_model = 'group'
    form_fields = ['sent_amount']

    @staticmethod
    def is_displayed(player: Player):
        return player.id_in_group == 1


class WaitForP1(WaitPage):
    pass


class SendBack(Page):
    form_model = 'group'
    form_fields = ['sent_back_amount']

    @staticmethod
    def is_displayed(player: Player):
        return player.id_in_group == 2

    @staticmethod
    def vars_for_template(player: Player):
        group = player.group

        return dict(tripled_amount=group.sent_amount * C.MULTIPLIER)


class ResultsWaitPage(WaitPage):
    after_all_players_arrive = set_payoffs


class Results(Page):
    pass


class Grade(Page):
    form_model = Player
    form_fields = ['grade', 'education']


class Thankyou(Page):
    pass


page_sequence = [Start, instructions, Questions, Send, WaitForP1, SendBack, ResultsWaitPage, Results, Grade, Thankyou
                 ]

Write a reply

Set forum username