oTree Forum >

If statement based on the number of participants in a session

#1 by oton


I am using an older version of oTree (3.4.0) and have two very specific group matching matrices. I would like oTree to choose one of them based on the number of participants in the session. I tried the following if statement using the self.session.vars['num_participants'] because 'num_participants' is listed as a session variable but I get a KeyError. Any ideas would be highly appreciated.

    def creating_session(self):
        if self.session.vars['num_participants'] == 12:
            self.set_group_matrix(Constants.grcomb12[Constants.rndcomblist[self.round_number - 1]])
        elif self.session.vars['num_participants'] == 13:
            self.set_group_matrix(Constants.grcomb13[Constants.rndcomblist[self.round_number - 1]])


#2 by oton

In case anyone needs this in the future, it turns out the issue was that the correct way to refer to the number of participants was session.num_participants, not session.vars['num_participants'].

Write a reply

Set forum username