Global variable as a dictionary


Do global variables support dictionaries? I want to create a dictionary as a global variable with a key/value pair that can be updated as needed. I don’t see an option to create the variable as a dictionary.

Any help would be great. Thanks!

Example: @foo = [“bar”:“bah”,“morebar”:“morebah”]


I would probably recommend keeping all combined global data to 2000 characters, or less.
(they take up space)

If your “dictionary” is quite small, it is easy to do.

  • Create Global variable(s), and choose “string” as type
  • Name it the first part of the pair
  • Edit any piston
  • Click on the global(s) to add data


So if there is limited space for global variables how would you suggest data that needs to be shared across pistons be stored?


I updated my description with an example of what I’d like to do.


Well, to be honest, I don’t think anyone has publicly mentioned a global size limit… but logically, there must be one. (and I assume the more data in variables, the less space available for pistons)

You can store data on a server (like the Raspberry Pi), or an online Google Spreadsheet, as seen here.

Writing to Google Sheets
Reading from Google Sheets

Any piston will be able to write to and read from those.


Before you get in too far, I should probably quote:

So, if your data is sensitive, I would use a private server.


Just to clarify, The links above for writing to and reading from google sheets do not require publishing the spreadsheet so the data remains private. The quote above was relative to a different, simpler method for accessing google sheets data which does require publishing on the web and therefore exposing the data.


Good to know! :+1:


Global variables use state in a groovy app, so they are limited to 100K bytes less whatever other state is being used. So yes they are limited.

I’m not aware of a method to create global variables programmatically. There may be a way to do this indirectly using [] references of this variable.


Perhaps the wording is a bit confusing though because your step 2 over there clearly states:

Just thought you should know.


Appreciate you pointing this out! My spreadsheet isn’t published and works fine. I think I copied this from the original source instructions. I will have to make an update. You just need the ID to put in the script and the script has to be published but not the spreadsheet. The script would provide access to the unpublished spreadsheet if you obtained that link but you would also have to know the spreadsheet name for the sensitive data (as long as you don’t put anything sensitive on the default spreadsheet). I will update the instructions accordingly. thanks again.