Global variable as a dictionary


#1

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”]


#2

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

#3

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


#4

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


#5

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
and
Reading from Google Sheets

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


Edit:

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

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


#6

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.


#7

Good to know! :+1:


#8

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.


#9

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

Just thought you should know.


#10

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.