In the past few months, oTree has many new features, because of oTree Lite, the new no-self format, and various other improvements that were made.
oTree Lite can still run apps written in the 3.x format. However, if you are starting a new project, it's recommended to use the newest syntax.
Some of these changes may look arbitrary, but in each case the change addresses a specific issue, either enabling new use cases, preventing certain errors, or making the functionality clearer or more consistent.
This table is also useful for new learners of oTree who are trying to understand code written before 2021.
Description | Old format (still works) | New format (recommended) | More info | Comment |
---|---|---|---|---|
App folder |
|
|
More info | |
Import statements |
|
|
More info | |
Template preamble |
|
|
More info | |
Template tags |
|
|
More info | |
Constants |
|
|
ALL CAPS version is new in 2022. Both formats are OK. | |
Model methods |
|
|
More info | |
User-defined functions |
|
|
More info | |
after_all_players_arrive (method definition style) |
|
|
||
after_all_players_arrive (method name style) |
|
|
The old format is not deprecated | |
before_next_page |
|
|
More info | |
participant.vars |
|
|
More info | This is just for convenience. You can still use participant.vars. |
Roles |
|
|
More info | |
Requirements files |
|
|
||
formfield |
|
|
More info | The old format is not deprecated |
formfield errors |
|
|
More info | |
Rounding numbers in templates |
|
|
More info | floatformat no longer works in oTree 5 |
Currency |
|
|
More info | |
Intentionally accessing a null (None) field |
|
|
More info |
@staticmethod
and (player: Player)
etc...If you are using a text editor to write your oTree code, it's recommended to add @staticmethod before all functions inside a page class, like is_displayed, vars_for_template, before_next_page, etc. They are sometimes omitted from this documentation for brevity. You can also add type annotations on all your functions. They are not mandatory but will help your editor provide better autocompletion.
If documentation says... | PyCharm users should type... | |||
---|---|---|---|---|
|
|
|||
|
|