1

Consider a game with 3 rounds. In every round the player makes a choice (stored in the variable choice).

Now, in the 3rd round I want to call someFunction and thereby access the choice made in the 2nd round.

Unfortunately someFunction returns None. I do not understand why. If I place the function call in a template file, everything works out fine.

Help would be appriciated - I ve been searching for hours.

class Subsession(BaseSubsession):
    def before_session_starts(self):
        if self.round_number == 3:
            for player in self.get_players():
                player.participant.vars['someKey'] = player.someFunction()

class Player(BasePlayer):
    choice = models.CharField(initial=None,
                                choices=['A','B','C'],
                                widget=widgets.RadioSelect()) 

    def someFunction(self):
        return self.in_round(2).choice

Why is this happening?

Ben L
  • 97
  • 1
  • 6

1 Answers1

1

the before_session_starts function is executed before the session starts (hence its name). Thus, when it is executed the player has not done his/her choice yet. That is why someFunction returns None.

You can set player.participant.vars['someKey'] = self.player.choice in the end of 2nd round, which will give you result you are looking for.

class Choice(Page):
    def before_next_page(self):
        if self.player.round_number == 2:
            player.participant.vars['someKey'] = self.player.choice
Philipp Chapkovski
  • 1,949
  • 3
  • 22
  • 43