oTree Forum >

Attribute Error when trying to create random groups after x players have arrived

#1 by Gabriel

Hi all,

I am trying to create an experiment where participants are randomly matched in groups of 2 before every round, but only every time 8 players have entered the waiting room (whereafter the waiting room clears). Since I currently have n=400, I don't believe I can use after_all_players_arrive().
        
However, in every instance where I have tried to create a list or tuple of randomized pairs and then return those, I get the error:

"Application error (500)
AttributeError: 'list' object has no attribute 'participant' "

What am I doing wrong here? Sample code below, for reference.

def group_by_arrival_time_method(subsession: Subsession, waiting_players):
    from random import shuffle

    if len(waiting_players) >= 8:
        shuffle(waiting_players)
        groups = [
            [waiting_players[0], waiting_players[1]],
            [waiting_players[2], waiting_players[3]],
            [waiting_players[4], waiting_players[5]],
            [waiting_players[6], waiting_players[7]]
        ]
        return groups
        
        
Optimally, I'm looking for something like an after_x_players_arrive function. Does anyone know a way to approach this?

Thank you!

Write a reply

Set forum username