oTree Forum >

how to use {field_name}_max() function and generate error messages accordingly

#1 by Yizhi_Wang (edited )

In my game, I have two variables (tax and public good provision). The maximum level of public good provision should be smaller than the tax amount. I am using the {field_name}_max() function to achieve this goal. However, it seems that the code does not work. It would not generate error message accordingly. Here are my codes:

class Player(BasePlayer):
    pga = models.IntegerField(min=1, max=100, label="Public Good Provision: ")
    pgb = models.IntegerField(min=1, max=100, label="Public Good Provision: ")
    taxa = models.IntegerField(min=1, max=100, label="Tax Amount: ")
    taxb = models.IntegerField(min=1, max=100, label="Tax Amount: ")


def pga_max(player):
    return player.taxa


def pgb_max(player):
    return player.taxb


def pga_error_message(player, value):
    print('Public good level is', value)
    if value > player.taxa:
        return 'Cannot offer public good more than your tax budget. '
        
The error seems related to player.taxa is null.

Many thanks for your help!

#2 by Yizhi_Wang (edited )

It seems that this error has something to do with the player.role I use. I have used 7 player roles. Please see attached my codes. Many thanks for your help!

Write a reply

Set forum username