oTree Forum >

Create a conditional app

#1 by GregorFHSU

Hello everybody,

I couldn´t find anything on this topic, so thank you in advance.

My problem is that I want to create two apps that are either played if someone is below or over an age limit. So my plan is:
1. Introduction to the experiment and question: "Are you below age 18 or over?"
2a. Only played if below 18
2b. Only played if over 18
3. Questionnaries for everyone

Can I work on this problem in "SESSION_CONFIGS" or how can I do this?

Best regards,

#2 by BonnEconLab

I haven’t tested the following, but it should work:

After you ask for your participants’ age, use app_after_this_page. See https://otree.readthedocs.io/en/latest/pages.html.

More specifically, in the settings.py file, you would define, say, app_sequence = ['elicit_age', 'app_if_minor', 'app_if_adult', 'survey'].

Let’s assume that within the __init__.py file of the elicit_age app, you define the player field player.age. For the page on which you ask your participants for their age, you should then be able to use

    def app_after_this_page(player, upcoming_apps):
        if player.age < 18:
            return 'app_if_minor'
            return 'app_if_adult'

On the final page of the app_if_minor app, you will also have to use app_after_this_page to skip to the survey app.

#3 by GregorFHSU

Thank you! 
I will test it and get back to you if ans how it worked.

#4 by GregorFHSU

Sorry for my late answer.
Everything, but the bots, is working fine. I don't really know what the problem is right now, so I can't give any tips on how to implement Bots.

Write a reply

Set forum username