# Cloud variables_

Please do not use these in your own project as is. There is a section at the end for how to do it properly, and I can help if you have some trouble.

These can be read from any number of times without using any bandwidth. There is a little bit of bandwidth when a variable is changed, but you can read any number of times other than that. The https? based blocks use bandwidth every time a variable is read, so this is better.

• Adding support for things that are not strings. Firebase supports this, but I don't use it. You can use json in the mean time. — Done. I also fixed a bug where mutating a cloud variable changed the local copy, but not the Firebase one.
• Adding support for bridge variables that go between projects. This would be fairly simple, with one additional root collection containing shared variables.
• Using the native variables instead of using new blocks. There would be a block to sync variables with the cloud. — Done.
• Support for mutating cloud lists. This is fairly complicated, because each update would have to be tagged with if it is a mutation or a change.

1. Get a google account. Firebase is a google service, so you will need an account. Most organizational accounts should work, but not all.
2. Go to https://console.firebase.google.com and create a project. I used spaceelephant-clouddata because my Snap! account is spaceelephant.
3. Start a web app and copy the config tree in place of mine.
4. Add Cloud Firestore. Make sure it isn't Realtime Database.
5. Set the security to something. All allowed is not good because anyone can do anything, none allowed isn't good because snap can't do the things it's supposed to do. Here is my code. It will allow snap to edit variables, but not to add more or delete them.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /current/project {
match /{project} {
match /{variable} {
allow create, delete: if false;
}
}
}
}
}

1. Go to the Firebase console and add a collection for your project. It must have the same name. Inside that collection, add a document with the same name as the variable. Add a field called value inside that document. Set it to a string. The console bypasses the security rules because you need to sign in to use it.
2. Run your Snap! project and use the cloud variable blocks. Do not run the set up firestore block. That is run automatically by the other blocks.

You’re that good with JavaScript? I can’t even learn python

It's not just javascript. It uses firebase, a serverless computing platform. Firebase is mostly like a server you write, but it has a free plan. You don't see how my JS could work because it doesn't work.

I can tell you that I’m only 10

Oh sorry

Well done!

What is the difference between Firestore and Realtime Database? Wouldn't a Realtime Database be better (just looking at its name) to implement cloud variables?

Queries in Firestore are shallow, and queries in Realtime Database are deep. For this specific example, it doesn't matter much. However, my code is for Firestore. Both work in real time, and I chose Firestore mostly because google recommends it above Realtime Database.

Thanks.
Another question: do the hashtable blocks work? If so, can you give me a short example? I tried to create an empty hashtable and to add a pair to it, but the replace block complains that the hashtable variable, to whom I assigned the value of the "empty hashtable" reporter, is an integer instead of an hashtable object.

They seem to work to me. I created a variable, set it to a hashtable, and the replace block seems to work. Do you have a screenshot of your specific case?

Another question: do you think it is faster having several cloud variables with simple values or just one cloud variable with complex (e.g. json) values?

The first one.JSON loads some extra data.