Assign values to Constants from SESSION_CONFIGS

231 views
Skip to first unread message

Bhagya Gunawardena

unread,
Oct 1, 2021, 9:00:57 AM10/1/21
to oTree help & discussion
Hello all,

I have a similar question as in the tread "SESSION_CONFIG to Constants" and checked the link mentioned in the answer. If I'm not mistaken, in "random_num_rounds" app, we set num_rounds to a larger number and display pages conditionally (based on random numbers). Is there a way where the experimenter set a fixed number of rounds (or set a value of any other variable) in session config and use it as a constant? For example, can I assign the value of "num_seq" and "num_rounds_per_seq" in the following code in the session config, so I can change the number of rounds when starting a session without changing the original code? (I'm using self format) 


class Constants(BaseConstants):
    name_in_url = 'New_Stages'
    players_per_group = None
    num_seq = 3
    num_rounds_per_seq = 10
    num_rounds = num_seq * num_rounds_per_seq

Thank you,

Bhagya 

Olaf Ghanizadeh

unread,
Oct 1, 2021, 10:40:18 AM10/1/21
to oTree help & discussion
I don't think you can access it in Constants, but you can access it in the subsession like this:

subsession.session.config['num_seq']

Bhagya Gunawardena

unread,
Oct 4, 2021, 8:44:42 AM10/4/21
to oTree help & discussion

Thank you for your reply.
 Yes, I tried self.session.config. The problem I have (in addition to the above) is that my main application has several rounds (which I wanted to change through session config) and I want to refer to the number of rounds the main app had in another app. Currently what I do is define a new constant in the following app and explicitly assign the number of rounds in the main app manually. But, I would like to change this value only at one point and then access that value through all the apps. (So if I want to change the number of rounds in the main app, I only have to change one point.)
Reply all
Reply to author
Forward
0 new messages