# How can I access to the properties of variable defined in an previous routine?

**URL:** <https://discourse.psychopy.org/t/how-can-i-access-to-the-properties-of-variable-defined-in-an-previous-routine/39928>\
**Category:** Builder\
**Created:** [May 6, 2024, 4:43pm UTC](https://discourse.psychopy.org/t/how-can-i-access-to-the-properties-of-variable-defined-in-an-previous-routine/39928 "2024-05-06T16:43:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veronica\_Domenici](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/veronica_domenici/32/41711_2.png) [@Veronica\_Domenici](https://discourse.psychopy.org/u/Veronica_Domenici)\
**Post date:** [May 6, 2024, 4:43pm UTC](https://discourse.psychopy.org/t/how-can-i-access-to-the-properties-of-variable-defined-in-an-previous-routine/39928/1 "2024-05-06T16:43:46Z")

</div>

**OS** (e.g. Win10): MacOS Ventura 13.4  
**PsychoPy version** (e.g. 1.84.x): 2023.2.3  
**Standard Standalone? (y/n)** y  
**What are you trying to achieve?:** Using a variable defined in a previous routine

**What did you try to make it work?:** By using PsychoPy Builder, I create a first routine in which I have several variables including a button. I would like to access the number of times the button was clicked in a second routine but I cannot get these result. I saw that in the .csv file created by PsychoPy at the end of the experiment, I have the property button.numClicks with the corresponding number (which reading the code seems to be created at the end of the first routine) but I don’t know how recall this button property in the next routine.  
Thanks for your help!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [May 7, 2024, 8:55am UTC](https://discourse.psychopy.org/t/how-can-i-access-to-the-properties-of-variable-defined-in-an-previous-routine/39928/2 "2024-05-07T08:55:19Z")

</div>

There’s a bug whereby button.numClicks is getting cleared at the end of the routine. Try setting a variable in End Routine e.g. buttonClicks = button.numClicks and then calling that. I tried to fix button.numClicks for the 2024.1.3 bugfix and got part way there but I think there might be a bit more to do. I haven’t had a chance to properly test it since our codesprint.

---

<div class="post-metadata">

**Author:** ![Veronica\_Domenici](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/veronica_domenici/32/41711_2.png) [@Veronica\_Domenici](https://discourse.psychopy.org/u/Veronica_Domenici)\
**Post date:** [May 7, 2024, 2:14pm UTC](https://discourse.psychopy.org/t/how-can-i-access-to-the-properties-of-variable-defined-in-an-previous-routine/39928/3 "2024-05-07T14:14:33Z")

</div>

Thank you for your answer! I tried to initialize an empty variable n\_click=None in ‘Begin Experiment’ and set it in EndRoutine as follows: n\_click= button.numClick. However, when I call n\_click in the second routine within a text variable ‘None’ appears, as if the final value of n\_click had not been updated or saved at the end of the first routine.  
I also attempted to not use button.numCliks by adding a conditional statement in each frame, that is:  
if (mouse.isPressedIn(button)) {  
chill\_pressed = true;  
n\_click += 1;  
and saving it in end routine but the result is the same as above.  
I will keep trying and if you have any other suggestions you are welcome!
