Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » How many variables I can create?
- Morimop
-
Scratcher
1000+ posts
How many variables I can create?
Currently, I'm working on a game, and I assume there are going to be a lot of variables. However, I'm afraid that there may be a variable limit, so that's why I'm asking this.
How many variables I can create, or is it endless (probably not)?
How many variables I can create, or is it endless (probably not)?
- han614698
-
Scratcher
1000+ posts
How many variables I can create?
Variables: No known limit, HOWEVER:
real_name_ack said:Cloud Variables: 10
I think it is infinite, however the JSON file limit is 5MB so you can't add more than a few thousand.
- awesome-llama
-
Scratcher
1000+ posts
How many variables I can create?
I think it is infinite, however the json file limit is 5 megabytes so you can't add more than a few thousand.^ This.
I decided to go and find an approximate number for how many variables could theoretically fit within that limit.
For a variable to be defined, it needs to exist like this:

Now, it depends on how much data you want to fit in to each variable to determine how many can be used.
Firstly, how much space is needed for a single variable?
The answer is num_of_bytes = 31 + name_length + data_length
If the variables were to store zeroes, then we could expect an extra 1 byte for the character. That makes it 32 + name_length.
The next step is to find a balance between variable count and length of names as the more variables you create, the more letters you need to name them.
You can name variables with printable ASCII as well as unicode, but I am only going to look at printable ASCII because I don't have enough time to figure out how Unicode works. There are 95 printable ASCII characters. That means having variable names of only 3 characters makes 857,375 permutations. I checked and this is the smallest length that can be used for the next step - finding how many fit in to 5 MB.
5 MB = 5,000,000 bytes.
5,000,000 / (32+3) = 142,857
So the answer is roughly 142,800 variables.
* Note that this ignores a couple of details which make the calculation inaccurate, but they shouldn't be big enough to worry about.
(e.g. the last item doesn't have a comma, I don't know what 5MB is exactly for Scratch's limit, there may be more than the printable characters that are usable)
Last edited by awesome-llama (Feb. 25, 2021 15:57:06)
- bobcat0701
-
Scratcher
1000+ posts
How many variables I can create?
snipedthanks for teaching math class today
- Flowermanvista
-
Scratcher
1000+ posts
How many variables I can create?
@awesome-llama: The limit is actually 5,250,000 bytes (about 5.007 MiB, although incorrectly quoted as
“5 MB” by authoritative sources such as the support article).
“5 MB” by authoritative sources such as the support article).
- Lemonadeinsummer
-
Scratcher
100+ posts
How many variables I can create?
Hey there! I think the limit is very high, so you probably don't have to worry about it. Hope this helped ^.^
- Discussion Forums
- » Questions about Scratch
-
» How many variables I can create?






