oTree Forum >

Payoff structure

#1 by FEDx

Hi everyone,
I'm trying to setting up a payoff structure like this:
import random

choice = {
    1: (7, 7),
    2: (8, 6.3),
    3: (9, 5.8),
    4: (10, 5.4),
    5: (11, 5),
    6: (12, 4.5),
    7: (13, 3.8),
    8: (14, 2.7),
    9: (14.5, 1.5),
    10: (14.6, 0)
}

if player.eg_switch in choice:
    player.selected_gamble = random.choice(choice[player.eg_switch])
    
player.payoff = player.selected_gamble
return

However I get an error "TypeError: player.selected_gamble is None".
File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/otree/database.py, line 597, in __getattribute__
Player(selected_gamble=None, eg_switch='2', round_number=1, id_in_group=1)

As if the system does not connect the two variables.

#2 by FEDx

Solved :)

Write a reply

Set forum username