oTree Forum >

Key Error

#1 by otree

Hello!

I have a two players game and I want to save the value inputted by player 1 (in this case be01a) also for player 2. To do that, I use the following code: 
    def before_next_page(self):
        self.participant.vars['be01a'] = self.group.be01a
        others = self.player.get_others_in_group()
        for p in others:
            p.participant.vars['be01a'] = self.group.be01a
            
Later on, I want to use the value of be01a in one of the pages. And to do that I use this code. 
    def js_vars(self):
        return dict(
            subtreatment = self.participant.vars['subtreatment'],
            sound_bad = self.participant.vars['be01a'],
            sound_good = self.participant.vars['be02a']
            )
However, I keep getting a key error related to sound_bad = self.participant.vars['be01a'], 

Thanks so much in advance for your help!

#2 by Victor

Hi! Im not sure this is what youre looking for but you can just call be01a from any player if that variable is on the group level AND the two players are in the same group. Hence I wonder what you are doing is necessary. Or do you want to share it across groups?

Write a reply

Set forum username