I am trying to implement a simple score counter in Otree (Python Library) by modifying the quiz game template to make it two players.
Eventually, I want this counter to update only on certain conditions, but for now, I'm just trying to add 10 after every round.
In models.py, I have defined a player class like so:
class Player(BasePlayer):
question_id = models.IntegerField()
confidence = models.FloatField(widget=widgets.Slider(attrs={'step': '0.01'}))
question = models.StringField()
solution = models.StringField()
submitted_answer = models.StringField(widget=widgets.RadioSelect)
is_correct = models.BooleanField()
total_score = models.IntegerField(initial = 0)
def other_player(self):
return self.get_others_in_group()[0]
def current_question(self):
return self.session.vars['questions'][self.round_number - 1]
def check_correct(self):
self.is_correct = self.submitted_answer == self.solution
def check_if_awarded_points(self):
self.get_others_in_group()[0].submitted_answer == self.submitted_answer == self.solution
def score_points(self):
self.total_score+=10
self.payoff += c(10)
The only relevant function above is "score points" which I call in the pages.py template like so:
class ResultsWaitPage(WaitPage):
def after_all_players_arrive(self):
for p in self.group.get_players():
p.score_points()
I then create a results page which shows me the results of the quiz after each question in order to test that either "total_score' or "pay-offs" is increasing by 10 each question.
class IntermediateResults(Page):
def vars_for_template(self):
return {
'total_score': [p.total_score for p in self.group.get_players()],
'total_payoff': [p.payoff for p in self.group.get_players()]
}
If I expose the values of total_payoff and total_score using Django, I see that their value is 10, and it never changes. I don't know why this is the case. Any thoughts?