oTree Forum >

get participants by role

#1 by charlotte

Hello everyone,

I am using the field "role" across apps and using the function get_player_by_role which does not work now that role is a participant field rather than a player field. I cannot use player.participant.role or even subsession.RECEIVER_ROLE (initialised in settings.py) in the def_payoffs function as it uses only group as an argument (and I don't seem to be able to add other arguments).

Has anyone got a solution? 
Here is the problematic bit:

def set_payoffs(group: Group):
    receiver = group.get_player_by_role(C.RECEIVER_ROLE)
    sender = group.get_player_by_role(C.SENDER_ROLE)
    if receiver.choice == 'Box A':
        receiver.payoff = C.boxA_receiver
        sender.payoff = C.boxA_sender
        receiver.payoff = C.boxB_receiver
        sender.payoff = C.boxB_sender
Thank you!

Write a reply

Set forum username