Passing data between rounds

750 views
Skip to first unread message

楊仲

unread,
Dec 8, 2021, 9:49:12 AM12/8/21
to oTree help & discussion
Hi,

I am building a Monty Hall Problem app with multiple rounds, and I want to provide the choice of "commit to a strategy". Once a player presses the commit button, I hope to disable some button in the template in future rounds.

Now I am using a participant variable to specify whether a player has committed. It seems that I can not call the variable before I assigned a value to it, which yields errors. Is there a method to give participant variables initial value before first round but not initialize it again before the second round? I have tried creating_session but that is working since I want to keep the value to following round. 

Thanks,
Chung Yang

楊仲

unread,
Dec 8, 2021, 9:51:03 AM12/8/21
to oTree help & discussion
I mean creating_session is not going to work. Sorry for the typo.

楊仲 在 2021年12月8日 星期三下午10:49:12 [UTC+8] 的信中寫道:

Chris Crabbe

unread,
Dec 8, 2021, 10:21:48 AM12/8/21
to 楊仲, oTree help & discussion
Hi Chung Yang -

The way that the oTree data model works is that player variables in different rounds are different things, stored in different places in the database - a "participant" is the oTree idea of a subject across the whole experiment.  A Participant is associated with many different Player objects (one per round).  https://otree.readthedocs.io/en/latest/conceptual_overview.html#participant

So, the logical place to store a participant's decision in one round so that you can initialize it to that value when the next round starts is in the participant.vars dict:  https://otree.readthedocs.io/en/latest/rounds.html#participant-fields

I would store the round 1 player's move in participant vars in the before_next_page method of the decision page in the first round (player.participant.vars['decision']=player.decision) and then load it into that field of the player in the next round (somewhere before the decision page, like its is_displayed() or vars_for_template() method:  (player.decision=player.participant.vars['decision'])

Thanks,
--Chris

--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/d195e262-16a1-4f6b-a6c6-077ffa8b7610n%40googlegroups.com.

楊仲

unread,
Dec 9, 2021, 1:10:36 AM12/9/21
to oTree help & discussion
Thanks. With your guide I have made it works.
ccr...@gmail.com 在 2021年12月8日 星期三下午11:21:48 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages