Problems in the sum of payoffs

87 views
Skip to first unread message

Andre P

unread,
Sep 10, 2021, 8:31:54 AM9/10/21
to oTree help & discussion
Hello guys, i'm trying to sum the payoffs in waitpage, so to do this in Group class I created a method set_payoffs, like this:

    def set_payoffs(group):
        p1 = group.get_player_by_role(Constants.p1_role)
        p2 = group.get_player_by_role(Constants.p2_role)

        if group.player_1 == 1 & group.player_2 == 1:
            p1.payoff += 1
            p2.payoff += 1
        elif group.player_1 == 0 & group.player_2 == 0:
            p1.payoff += 0.6
            p2.payoff += 0.6
        elif group.player_1 == 1 & group.player_2 == 0:
            p1.payoff += 0.3
            p2.payoff += 1.2
        elif group.player_1 == 0 & group.player_2 == 1:
            p1.payoff += 1.2

So, following the documentation I tried in a waitpage use after_all_players_arrive, like this:

class ControlWaitPage(WaitPage):
    
    after_all_players_arrive = 'set_payoffs'

But I got a error:
Application error (500)Exception: "set_payoffs" not found in <module 'seller' from '/home/user/otree/project2/seller/__init__.py'>

Chris @ oTree

unread,
Sep 10, 2021, 12:00:53 PM9/10/21
to oTree help & discussion
Not in the Group class. it should be at the outer level, outside of any class.



You can also remove the quotes from 'set_payoffs'.

Andre P

unread,
Sep 10, 2021, 12:53:18 PM9/10/21
to oTree help & discussion
Chris , tks I'm very grateful

But,  now I have another problem, I made the changes has you suggest, but I got that error:
Application error (500)TypeError: unsupported operand type(s) for &: 'int' and 'Currency'

I need to define in different away the payoff?

Chris @ oTree

unread,
Sep 10, 2021, 12:55:36 PM9/10/21
to oTree help & discussion
Don't use "&". use "and"

Andre P

unread,
Sep 10, 2021, 1:01:33 PM9/10/21
to oTree help & discussion
hum, ok tks!
Reply all
Reply to author
Forward
0 new messages