oTree Forum >

how to reference partner's variables in multiplayer game?

#1 by rvman0523

Hello, I have a sequential game (consisting of 2 apps, because "match by arrival time" happens a few pages into the survey) in which Player A makes the first move, and Player B is notified of the results.

1. When Player A makes move, they see information about Player B. (Ex. "Player B is (gender), residing in (location)) This is information propagated from a screening survey that Player B filled out in app sequence 1. My question is: how do you reference the value of the variable from the person you are paired with? 

2. Similarly, once Player A makes a decision ($ amount), this amount is communicated to Player B. Same question as above, but this would be in the same app sequence (sequence 2).

Thanks!

#2 by Daniel_Frey

If you have two different apps, you need to store the player's answers in a participant field: https://otree.readthedocs.io/en/latest/rounds.html#participant-fields

Then, you can access the other player's answers by accessing their Player-Model:

# for the Page Player A can see Player B's answers
def vars_for_template(player: Player):
    player_b = player.group.get_player_by_id(2) # I suppose Player A is ID 1, Player B is ID 2 in your setup

    return dict(gender=player_b.participant.gender, location=player_b.participant.location)
    
    
And similar for the other player, though you don't necessarily need participant values (since it is the same app). If Player B will see the page before Player A makes his/her decision and the page should update, you need live pages: https://otree.readthedocs.io/en/latest/live.html

Hope that helps!

Write a reply

Set forum username