## Discuss Scratch

- Discussion Forums
- » Help with Scripts
- » Is there a maximum variable length?

- -Fuzzbutt-
- New to Scratch

8 posts

### Is there a maximum variable length?

I was just wondering if there is a maximum length for a variable, because a project I'm working on requires it to be at least 21600 digits long, and it would be nice if it could be 1382400 digits long. But right now it seems like it cannot get past 10240 digits.

Thanks!

-Fuzzbutt-

Thanks!

-Fuzzbutt-

You have just read great wisdom from -Fuzzbutt-.

- -Fuzzbutt-
- New to Scratch

8 posts

### Is there a maximum variable length?

Possibly. The project is a screen scanner that finds the color of pixels on the screen. Then it records the color in an 8-digit number, adds it to a variable, and saves it to be drawn again any time from pen. 10240 digits is probably the limit. Could you try compressing the data if possible?

You have just read great wisdom from -Fuzzbutt-.

- myhf
- Scratcher

13 posts

### Is there a maximum variable length?

A variable can hold up to 10240 unicode characters. You can use a reasonable-size lookup table to convert each 1-byte number into a unique character, or an absurdly large lookup table to convert larger numbers into unique characters.

define save: (number)

set [lookup table v] to [0123456789abcdefghijklmnopqrstuvwxyzABC...]

set [string v] to (join [(string)] [(letter (number) of [lookup table])])

define restore: (string)

set [i v] to [1]

repeat until <[i] = (length of [(string)]) >

set [char v] to (letter (i) of [(string)])

set [j v] to [1]

set [number v] to []

repeat until <<[j] = (length of [(lookup table)]) > or <not <[(number)] = [ ]>>>

if <(letter (j) of [(lookup table)]) = [(char)]> then

set [number v] to (j)

... // do something with number

end

end

change [i v] by (1)

end

- -Fuzzbutt-
- New to Scratch

8 posts

### Is there a maximum variable length?

I kinda not really get that. But I get the general idea. And now that I think of it, that would be a good way to do it. I could also do it with a list to simplify it. A variable can hold up to 10240 unicode characters. You can use a reasonable-size lookup table to convert each 1-byte number into a unique character, or an absurdly large lookup table to convert larger numbers into unique characters.define save: (number)

set [lookup table v] to [0123456789abcdefghijklmnopqrstuvwxyzABC...]

set [string v] to (join [(string)] [(letter (number) of [lookup table])])

define restore: (string)

set [i v] to [1]

repeat until <[i] = (length of [(string)]) >

set [char v] to (letter (i) of [(string)])

set [j v] to [1]

set [number v] to []

repeat until <<[j] = (length of [(lookup table)]) > or <not <[(number)] = [ ]>>>

if <(letter (j) of [(lookup table)]) = [(char)]> then

set [number v] to (j)

... // do something with number

end

end

change [i v] by (1)

end

You have just read great wisdom from -Fuzzbutt-.

- 8bitprogrammer
- Scratcher

10 posts

### Is there a maximum variable length?

Why dont you do 2 variables joined together?

(join (Part 1) (Part 2))Then you can technically make infinite length, “Variables”

*Last edited by 8bitprogrammer (May 6, 2016 12:41:18)*

- drmcw
- Scratcher

1000+ posts

### Is there a maximum variable length?

Using a list is the only way to break the 10240 limit. Store each character in a list then when you want to use the whole string use the list reporter

https://scratch.mit.edu/projects/24934494/

https://scratch.mit.edu/projects/24934494/

*Last edited by drmcw (May 6, 2016 13:38:14)*

- jerrymonkey
- Scratcher

28 posts

### Is there a maximum variable length?

No no no no no no no You guys are wrong.

A standard “Global Variable” (Is not a cloud variable, but for all sprites) can handle –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (Numbers) which is a “Long” datatype.

And so if you do 3213546543132456315635431234523543 mod 2 you will get 0 (Overloads and should get 1)

A standard “Global Variable” (Is not a cloud variable, but for all sprites) can handle –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (Numbers) which is a “Long” datatype.

And so if you do 3213546543132456315635431234523543 mod 2 you will get 0 (Overloads and should get 1)

*Last edited by jerrymonkey (Feb. 11, 2017 10:36:03)*

- deck26
- Scratcher

1000+ posts

### Is there a maximum variable length?

If you build it up character by character and treat it as text a variable will hold 10240 characters - if you're using join to create it it is going to be treated as text anyway. No no no no no no no You guys are wrong.

A standard “Global Variable” (Is not a cloud variable, but for all sprites) can handle –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (Numbers) which is a “Long” datatype.

And so if you do 3213546543132456315635431234523543 mod 2 you will get 0 (Overloads and should get 1)

So perfectly possible to hold 10240 digits in a variable but you have to be careful how you use it - don't treat it as a number!

- drmcw
- Scratcher

1000+ posts

### Is there a maximum variable length?

No no no no no no no You are wrong. No no no no no no no You guys are wrong.

A standard “Global Variable” (Is not a cloud variable, but for all sprites) can handle –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (Numbers) which is a “Long” datatype.

And so if you do 3213546543132456315635431234523543 mod 2 you will get 0 (Overloads and should get 1)

- 4424dev
- Scratcher

1 post

### Is there a maximum variable length?

This is so Scratch can handle the variables. Why is there a imit anyway?

- deck26
- Scratcher

1000+ posts

### Is there a maximum variable length?

Most computer languages (if not all) will set limits for each variable type - generally based on the number of bytes allocated to each variable. Why is there a imit anyway?

- Charles12310
- Scratcher

1000+ posts

### Is there a maximum variable length?

That's what I usually so for very long strings. Using a list is the only way to break the 10240 limit. Store each character in a list then when you want to use the whole string use the list reporter

https://scratch.mit.edu/projects/24934494/

Click This Link For Some Secrets About Me!

A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!

- capecod18
- Scratcher

6 posts

### Is there a maximum variable length?

how do you lower a variable size? i need the variable to be only 3, but the lowest i can get is 100

- RealTheFluffyKing
- Scratcher

1 post

### Is there a maximum variable length?

Use the block set (variable) to (3)

*Last edited by RealTheFluffyKing (Dec. 8, 2018 05:30:05)*

- McNichollFam
- Scratcher

2 posts

### Is there a maximum variable length?

my project needs a very long cloud variable so i can't use the list workaround.

- codeman1044
- Scratcher

1000+ posts

### Is there a maximum variable length?

Please don't necropost. If you need help with a project, create your own topic.

This is my signature, which shows up every time I post and is automatic. To make a signature of your own, locate the “Change your signature” option in the bottom left of the Discussion Home.

I am nothing if not consistently inconsistent.

Snap! is a website that offers block coding like Scratch, but also offers the creation of your own blocks and writing JavaScript functions. The adventurous should consider checking it out!

Potentially useful tutorials and topic coverage

If you want to see a new tutorial added to this, feel free to leave a suggestion on my profile.

- Discussion Forums
- » Help with Scripts
- » Is there a maximum variable length?