ページ

参加者に表示される各ページは、 Page によって定義されます。

ページの順序は page_sequence で指定します。

ゲームに複数のラウンドがある場合は、この順序が繰り返されます (ラウンド 参照)。

Page は以下のようなメソッドや属性を持つことができます。

is_displayed()

ページを表示すべき場合には True を、ページをスキップすべき場合には False を返すようにこの関数を定義します。この関数が省略された場合は、そのページは表示されます。

例えば、各グループの P2 にだけページを表示する場合は以下のようになります:

@staticmethod
def is_displayed(player):
    return player.id_in_group == 2

また、ラウンド 1 だけページを表示する場合は以下のようになります:

@staticmethod
def is_displayed(player):
    return player.round_number == 1

多くのページで同じルールを繰り返す必要がある場合は、 app_after_this_page を使用してください。

vars_for_template()

テンプレートに変数を渡す場合に使用します。例えば、次のようにします:

@staticmethod
def vars_for_template(player):
    a = player.num_apples * 10
    return dict(
        a=a,
        b=1 + 1,
    )

このとき、テンプレートでは次のように ab にアクセスできます:

Variables {{ a }} and {{ b }} ...

oTree automatically passes the following objects to the template: player, group, subsession, participant, session, and C. You can access them in the template like this: {{ C.BLAH }} or {{ player.blah }}.

ユーザーがページを更新すると、 vars_for_template は再実行されます。

before_next_page()

ここでは、フォームの検証後、プレイヤーが次のページに進む前に実行されるコードを定義します。

is_displayed でページがスキップされた場合は、 before_next_page もスキップされます。

例:

@staticmethod
def before_next_page(player, timeout_happened):
    player.tripled_apples = player.num_apples * 3

timeout_seconds

タイムアウト を参照

Wait pages

Wait page を参照

ページ順序のランダム化

ラウンドを使ってページの順番をランダムにすることができます。 こちら で例を確認できます。

app_after_this_page

アプリ全体をスキップするには、 app_after_this_page を定義します。例えば、次のアプリにスキップするには、次のようにします:

@staticmethod
def app_after_this_page(player, upcoming_apps):
    if player.whatever:
        return upcoming_apps[0]

upcoming_apps は、 app_sequence (文字列のリスト) の残りの部分です。したがって、最後のアプリにスキップするには、 upcoming_apps[-1] を返すようにします。また、ハードコードされた文字列を返すこともできます (ただし、その文字列が upcoming_apps に含まれている必要があります):

@staticmethod
def app_after_this_page(player, upcoming_apps):
    print('upcoming_apps is', upcoming_apps)
    if player.whatever:
        return "public_goods"

この関数が何も返さなかった場合、プレイヤーは通常通り次のページに進みます。