# Sharing variables between different instance mode sketches

**URL:** https://discourse.processing.org/t/sharing-variables-between-different-instance-mode-sketches/19264
**Category:** Coding Questions
**Created:** [March 31, 2020, 9:10pm UTC](https://discourse.processing.org/t/sharing-variables-between-different-instance-mode-sketches/19264 "2020-03-31T21:10:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![calornorte](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/calornorte/32/6066_2.png) [@calornorte](https://discourse.processing.org/u/calornorte)
#### Post date: [March 31, 2020, 9:10pm UTC](https://discourse.processing.org/t/sharing-variables-between-different-instance-mode-sketches/19264/1 "2020-03-31T21:10:33Z")

</div>

or having a global variable that could be accessed by different instance mode sketches.  
I have been looking around but I don’t seem to understand how to do it, any example that could illuminate me?

best!

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 1, 2020, 12:08am UTC](https://discourse.processing.org/t/sharing-variables-between-different-instance-mode-sketches/19264/2 "2020-04-01T00:08:59Z")

</div>

Anything declared using keywords `var` & `function` in the global context can be accessed everywhere.

As an example of it, in the sketch below the variable _sketches_ is declared using `var` in all files but the main 1, and is accessed by the main file:  
https://www.openprocessing.org/sketch/861749/embed/?

https://glitch.com/embed/#!/embed/radio-pick-active-sketch?path=sketches/0.js&previewSize=0&sidebarCollapsed=false

---

<div class="post-metadata">

### Author: ![calornorte](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/calornorte/32/6066_2.png) [@calornorte](https://discourse.processing.org/u/calornorte)
#### Post date: [April 4, 2020, 10:20pm UTC](https://discourse.processing.org/t/sharing-variables-between-different-instance-mode-sketches/19264/3 "2020-04-04T22:20:23Z")

</div>

Hello! thanks for the answer!  
honestly, that code you posted was difficult for me to understand.  
but I did manage to understand better how the namespace on my sketch can be created globally and later be called from another sketch under it’s “name.var”, much simpler than I realised. ! thank you!
