#1 by annesirbu
Hello everyone! I am having some trouble with displaying a variable that has been defined and used in the previous app. I checked the section 'Passing data between rounds or apps' https://otree.readthedocs.io/en/latest/rounds.html#passing-data-between-rounds-or-apps and wrote this code: prev_player = player.in_previous_apps() print(prev_player.payoff) I. am getting the following error: "AttributeError: module 'otree.models.player' has no attribute 'in_previous_apps' ". Do you know how I could fix this (where to properly define it) or have another solution that would work? I would be very grateful! Kind regards, Anne
#2 by Charlie_T
Hi Anne, If you want to pass between apps I am fairly sure you will need to pass the player data to the participant level. https://otree.readthedocs.io/en/latest/rounds.html#participant-fields The individual in the experiment is a participant, and they can take on different player roles during each app, so to get information from a previous app you need to pass it up to the participant first. https://otree.readthedocs.io/en/latest/conceptual_overview.html#participant. If you really are just interested in passing payoffs between apps, participant already has a payoff attribute in it. https://otreecb.netlify.app/reference/attributes_and_methods.html At least in my case, I have not had to pass payoff to the participant, instead the payoff is accurately tracked across the different apps. You can display this in the HTML by using {{ participant.payoff }}. If you want to display something else then you will need to add it as an attribute under participant. To do this, add it in the settings.py file under PARTICIPANT_FIELDS. Again to use what I am doing as an example, participants can contribute money in one app. So in settings I have PARTICIPANT_FIELDS = ['contribution']. In the app I add contribution to the player formfields as normal. I added a static method to the page where I ask for the contribution in order to pass that information to the participant: @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant participant.contribution = player.contribution In the HTML I can add {{ participant.contribution }} to display the contribution the player made in the app or in later apps. I hope that helps, Charlie
#3 by annesirbu
Hi Charlie, Thank you so much for your reply! It helped me a lot! I wish you a great day! Best regards, Anne