I am trying to create a simple counter in Otree that give a message when I don't have the correct answer in an 0tree form and also count the total attempts that a subject did before he/she got the right answer (I am trying to count the mistakes for each subject in each question).
I have the next code, but this code don't add anything in the form when someone make a mistake.
class CRT1(Page):
#def is_displayed(self):
#return self.player.tipo == 1
form_model = 'player'
form_fields = ['CRT1', 'incorrect_attempts1']
def CRT1_error_message(self, values):
print('Escogiste', values)
if values != 2:
return 'No lo olvides, sólo la respuesta seleccionada por el mayor número de los participantes en una sesión es la más seleccionada.'
self.player.incorrect_attempts1 += 1
print(incorrect_attempts1
if someone can give a idea of how to make this code works would be great, thanks in advance.
You return before adding to the counter. Do like that:
def CRT1_error_message(self, values):
print('Escogiste', values)
if values != 2:
self.player.incorrect_attempts1 += 1
return 'No lo olvides, sólo la respuesta seleccionada por el mayor número de los participantes en una sesión es la más seleccionada.'
Be sure that incorrect_attempts1
has initial=0