#1 by jrm0094
I am trying to create a penalty for when a player gets an answer wrong three times in a row. I have a player.penalty variable that I am incrementing by 1 for every wrong answer, and I am setting my participant.penalty variable to the player.penalty. For some reason, the players penalty will not go above 1. I think that I am missing just one small thing, because I have been able to utilize participant fields before, but I do not remember how.
Here is my code for the page where penalty is checked:
class AddNumbers(Page):
form_model = "player"
form_fields = ["number_entered"]
timer_text = "Time left in counting game:"
get_timeout_seconds = get_timeout_seconds
@staticmethod
def is_displayed(player: Player):
return get_timeout_seconds(player) > 0 and player.goal_complete == False and player.game_done == False
@staticmethod
def vars_for_template(player: Player):
participant = player.participant
the_matrix_and_zeros = table_creation(player)
matrix_and_zeros = [the_matrix_and_zeros[i] for i in range(len(the_matrix_and_zeros))]
matrix_table = matrix_and_zeros[0]
#print("participant goal set: ", participant.goal_set)
player.goal_set = participant.goal_set
print("player goal set: ", player.goal_set)
print("participant goal complete: ", participant.goal_complete)
player.goal_complete = participant.goal_complete
print("player goal complete: ", player.goal_complete)
if player.goal_set == True and player.goal_complete == False:
player.goal_left = participant.goal_left
print("goal left: ", player.goal_left)
player.goal_set = participant.goal_set
print("goal set:", player.goal_set)
if player.goal_left > 0 and player.goal_set == True:
goal = participant.goal_left
return {
"matrix_table": matrix_table,
"goal": goal
}
else:
return {
"matrix_table": matrix_table
}
else:
return {
"matrix_table": matrix_table
}
@staticmethod
def before_next_page(player: Player, timeout_happened):
participant = player.participant
player.answered = True
participant.answered = player.answered
if player.zeros_actual == player.number_entered:
player.penalty == 0
participant.penalty = player.penalty
player.payoff += C.payment_per_correct_answer
player.goal_left -= 1
participant.goal_left = player.goal_left
print("participant goal left: ", participant.goal_left)
player.correct_answer = True
participant.correct_answer = player.correct_answer
print("participant correct answer: ", participant.correct_answer)
if player.goal_left <= 0 and player.goal_set == True:
print("goal is complete!")
player.goal_complete = True
participant.goal_complete = player.goal_complete
else:
return
else:
player.correct_answer = False
participant.correct_answer = player.correct_answer
player.penalty += 1
participant.penalty = player.penalty
if player.penalty == 3:
player.payoff -= C.payment_per_correct_answer
if player.payoff < 0:
player.payoff = 0
print("player penalty: ", player.penalty)
print("penalty: ", participant.penalty)
print("participant correct answer: ", participant.correct_answer)
Near the end of the code I gave is where you will find where I am setting the players penalty. If anyone has an idea on how to fix this issue, I would greatly appreciate it. Thank you.