#1
by
lucilaa
Hello, I don't know what is happening, but the code works fine when timeout_seconds is 8 seconds or less. But when it is longer, 'm_l': self.player.participant.vars['m_l'] and 'm_t': self.player.participant.vars['m_t'] remain constant every round. class WP(WaitPage): template_name = 'sbe/WP.html' def vars_for_template(self): round_num = self.subsession.round_number for_margins_left = range(30, 1240 + 1, 15) for_margins_top = range(20, 720 + 1, 15) if round_num <= Constants.num_trial_rounds: for g in self.subsession.get_groups(): num_dots = g.get_player_by_id(1).participant.vars['dots_displayed_trial'][(round_num - 1)] margins_left = random.sample(for_margins_left, num_dots) margins_top = random.sample(for_margins_top, num_dots) for p in g.get_players(): p.participant.vars['m_l'] = margins_left p.participant.vars['m_t'] = margins_top else: for g in self.subsession.get_groups(): num_dots = g.get_player_by_id(1).participant.vars['dots_displayed'][(round_num - Constants.num_trial_rounds - 1)] margins_left = random.sample(for_margins_left, num_dots) margins_top = random.sample(for_margins_top, num_dots) for p in g.get_players(): p.participant.vars['m_l'] = margins_left p.participant.vars['m_t'] = margins_top return { 'round_num': round_num, } class PreDots(Page): timeout_seconds = 10 def vars_for_template(self): round_num = self.subsession.round_number if round_num <= Constants.num_trial_rounds: self.player.num_of_dots = self.player.participant.vars['dots_displayed_trial'][(round_num - 1)] else: self.player.num_of_dots = self.player.participant.vars['dots_displayed'][(round_num - Constants.num_trial_rounds - 1)] return { 'role': self.player.participant.vars['role'], 'num_dots': self.player.num_of_dots, 'round_num': round_num, 'round_count': round_num - Constants.num_trial_rounds, 'm_l': self.player.participant.vars['m_l'], 'm_t': self.player.participant.vars['m_t'] }
#2
by
lucilaa
the error happens when the page sequence goes "WP PreDots WP Prots WP PreDots" (when those are the only two pages) (and timeout_seconds = 9 or above) if I add a third page "WP PreDots NewPage WP Prots NewPage WP PreDots NewPage" then the code works fine, even if timeout_seconds is above 8
#3
by
Chris_oTree
It’s recommended to do any calculations like this in after_all_players_arrive, not vars_for_template.
#4
by
lucilaa
Is it okay to use "for g in self.subsession.get_groups():" or is it a problem to "call" all groups, given that not all of them will get to the waitpage at the same time?
#5
by
Chris_oTree
Usually it doesn't make sense conceptually to do this, since why would you modify the values of groups that may be ahead or behind in the game?
#6
by
lucilaa
I just saw that in the documentation it says "In oTree 2.3 and earlier, after_all_players_arrive was a method, i.e. def after_all_players_arrive(self):. However, the new format is better and you should use it instead." My requirements file says "otree>=3.4.0,<5" I was wondering if it would be a problem if I use "def after_all_players_arrive(self):" in pages.py in the waitpage. I need a list of numbers to be random every round but equal for all players in the same group. Can I still use "def after_all_players_arrive(self):" in otree>=3.4.0,<5? Is it not recommended because the option of setting the function in "class Group(BaseGroup):" is easier or is it not recommended because I might get an error while running the experiment?
#7
by
Chris_oTree
Using that syntax won’t help with your problem. Why can’t you define a group method?
#8
by
lucilaa
At the moment it is working (I am using self.group.get_players() instead of "for g in self.subsession.get_groups():", so I am not calling all groups anymore, right?), but I was wondering if using "def after_all_players_arrive(self):" can result in some unexpected error, I am not sure why it stopped being recommended. If I define a group method, will the random portion be executed every round? I need the numbers to change every round