Discuss Scratch

WizNGames
Scratcher
64 posts

Variables Keep On Saying "Infinity"

Hi, I'm trying to make a project where it needs very high variables but every time i go to like a character limit of 1000 or something it starts to say “Infinity”. Is this normal for it to say this and, will it still work even if it says “Infinity”?
gor-dee
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

A variable can hold a number like that as a string but you won't be able to do any maths with it. Why do you need such long numbers? Maybe there is an alternative way of doing what you want.
WizNGames
Scratcher
64 posts

Variables Keep On Saying "Infinity"

gor-dee wrote:

A variable can hold a number like that as a string but you won't be able to do any maths with it. Why do you need such long numbers? Maybe there is an alternative way of doing what you want.
The reason why i need these long numbers is I'm trying to do an encode/decoding with cloud variables. I'm very slightly new to cloud variables, so i dunno if it can still be a string.

Last edited by WizNGames (Jan. 17, 2020 23:59:05)

gor-dee
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

When you do encoding letters to numbers you have to use the
(join [] [])
block which will make Scratch think the number is a string and you can make very long numbers this way BUT cloud variables have a limit of 256 digits so you will have to split your data over several cloud variables to get a decent size list
WizNGames
Scratcher
64 posts

Variables Keep On Saying "Infinity"

gor-dee wrote:

When you do encoding letters to numbers you have to use the
(join [] [])
block which will make Scratch think the number is a string and you can make very long numbers this way BUT cloud variables have a limit of 256 digits so you will have to split your data over several cloud variables to get a decent size list
Bump! I cannot split it into several cloud variables on my project bc I'm using up all of them already. Also i thought it had a character limit of 10000
gor-dee
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

WizNGames wrote:

Bump! I cannot split it into several cloud variables on my project bc I'm using up all of them already. Also i thought it had a character limit of 10000
Nope. They were limited to 128 digits with no Hex (previously supported) in Feb 2018 then later this was increased to 256
https://scratch.mit.edu/discuss/topic/291775/?page=1
WizNGames
Scratcher
64 posts

Variables Keep On Saying "Infinity"

gor-dee wrote:

WizNGames wrote:

Bump! I cannot split it into several cloud variables on my project bc I'm using up all of them already. Also i thought it had a character limit of 10000
Nope. They were limited to 128 digits with no Hex (previously supported) in Feb 2018 then later this was increased to 256
https://scratch.mit.edu/discuss/topic/291775/?page=1
What do you mean by it changing from 128 to 256? I looked at the link, and all it showed was that 256 turned to 128? Also, i thought the character limit was 10240 when i looked at some topics. I'm confused
ok425
Scratcher
6 posts

Variables Keep On Saying "Infinity"

If you reach a large number on a variable (like if the variable keeps rapidly squaring itself) when you exceed (about) 1e+310 then the variable will display as infinity, probably to prevent lag and crashes. This is all based on my observations. How to do this: variable:>1 code: (forever: set variable to (variable*variable)) another example:
when green flag clicked
set [variable name] to (2)
forever
set [variable name] to ((variable name) * (variable name))
end

Last edited by ok425 (Sept. 14, 2020 00:47:19)

game-titan
Scratcher
79 posts

Variables Keep On Saying "Infinity"

WizNGames wrote:

What do you mean by it changing from 128 to 256? I looked at the link, and all it showed was that 256 turned to 128? Also, i thought the character limit was 10240 when i looked at some topics. I'm confused

From my own experimentation, while you can set more than 256 characters, and it might even appear to work for a while, the value won't actually persist.

Subscribe to or visit Game Titan YouTube channel for tutorials on games, programming and Scratch
deck26
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

Cloud variables were almost unlimited at first. The limit of 10240 characters (decimal or hexadecimal) was a result of using join and could be bypassed by creating a list of single characters and assigning that to a variable.

Not sure when the hex option went but the ST reduced cloud vars to 128 digits not long before Scratch 3 came along at which point it increased to 256 digits and that's where we are at the moment.

Using join, as @gor-dee says, means the variable is treated as a text string of digits rather than a number which stops Scratch trying to show it using scientific notation or hitting problems with infinity as you are.

If you assign more than 256 digits to a cloud variable the extra data will not be written to the cloud. Not sure if the data up to the 256 limit gets written or the project just doesn't try to write to the cloud in those circumstances. The project might still react as if the data has been written as the variable is just being treated as a normal variable at that point which can cause confusion.
Just_ng
Scratcher
500+ posts

Variables Keep On Saying "Infinity"

deck26 wrote:

Cloud variables were almost unlimited at first. The limit of 10240 characters (decimal or hexadecimal) was a result of using join and could be bypassed by creating a list of single characters and assigning that to a variable.

Not sure when the hex option went but the ST reduced cloud vars to 128 digits not long before Scratch 3 came along at which point it increased to 256 digits and that's where we are at the moment.

Using join, as @gor-dee says, means the variable is treated as a text string of digits rather than a number which stops Scratch trying to show it using scientific notation or hitting problems with infinity as you are.

If you assign more than 256 digits to a cloud variable the extra data will not be written to the cloud. Not sure if the data up to the 256 limit gets written or the project just doesn't try to write to the cloud in those circumstances. The project might still react as if the data has been written as the variable is just being treated as a normal variable at that point which can cause confusion.

What do you mean by join?


SMKAS
Scratcher
500+ posts

Variables Keep On Saying "Infinity"

S/he means this:
(join [apple] [banana])

When Default Text Goes here :: events hat
switch costume to Default ::looks
move Default steps ::motion
play Default Sound for Default Beats :: sound
broadcast Deault ::events
ask Default Text and wait :: sensing
(answer )=Default Text :: operators
set [Default v] to Default :: variables
add Default to [Default v] ::list
define Default
Default Text goes here:: custom
deck26
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

If you do this

set [var1 v] to [25]   // this will be treated as a number
set [var2 v] to [57] // as will this
set [var1 v] to (join (var1) (var2)) // the result is not a number, it's a text string containing 2557

But if you then did this

set [var1 v] to ([2] * (var1))   // var1 will be a number now; you've effectively told Scratch you want to use it as a number

Basically, don't apply numeric operations to cloud variables if you want to get them to hold long strings of digits.

Last edited by deck26 (Sept. 14, 2020 09:30:00)

moew_cat
Scratcher
51 posts

Variables Keep On Saying "Infinity"

var1 will be a number now; you've effectively told Scratch you want “ot”
huh??????????????????????????????????????? ::  hat
think about it for (10) secs
deck26
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

moew_cat wrote:

var1 will be a number now; you've effectively told Scratch you want “ot”
huh??????????????????????????????????????? ::  hat
think about it for (10) secs
Never seen the point of pointing out obvious typos.
Just_ng
Scratcher
500+ posts

Variables Keep On Saying "Infinity"

deck26 wrote:

If you do this

set [var1 v] to [25]   // this will be treated as a number
set [var2 v] to [57] // as will this
set [var1 v] to (join (var1) (var2)) // the result is not a number, it's a text string containing 2557

But if you then did this

set [var1 v] to ([2] * (var1))   // var1 will be a number now; you've effectively told Scratch you want to use it as a number

Basically, don't apply numeric operations to cloud variables if you want to get them to hold long strings of digits.



So… a string is considered as one digit?


deck26
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

Just_ng wrote:

deck26 wrote:

If you do this

set [var1 v] to [25]   // this will be treated as a number
set [var2 v] to [57] // as will this
set [var1 v] to (join (var1) (var2)) // the result is not a number, it's a text string containing 2557

But if you then did this

set [var1 v] to ([2] * (var1))   // var1 will be a number now; you've effectively told Scratch you want to use it as a number

Basically, don't apply numeric operations to cloud variables if you want to get them to hold long strings of digits.



So… a string is considered as one digit?
No, why do you say that? A string can be anything from blank to lots of digits. Or indeed any mixture of digits, letters and other characters.

Last edited by deck26 (Sept. 14, 2020 11:36:59)

Just_ng
Scratcher
500+ posts

Variables Keep On Saying "Infinity"

deck26 wrote:

Just_ng wrote:

deck26 wrote:

If you do this

set [var1 v] to [25]   // this will be treated as a number
set [var2 v] to [57] // as will this
set [var1 v] to (join (var1) (var2)) // the result is not a number, it's a text string containing 2557

But if you then did this

set [var1 v] to ([2] * (var1))   // var1 will be a number now; you've effectively told Scratch you want to use it as a number

Basically, don't apply numeric operations to cloud variables if you want to get them to hold long strings of digits.



So… a string is considered as one digit?
No, why do you say that? A string can be anything from blank to lots of digits. Or indeed any mixture of digits, letters and other characters.


So… whats the use of using join?


SMKAS
Scratcher
500+ posts

Variables Keep On Saying "Infinity"

Just_ng wrote:

So… whats the use of using join?
I think its too make it be treated as a “string” or something, since its a “string” and not a number, it probably exceed the usual limit of the variable, not sure.

When Default Text Goes here :: events hat
switch costume to Default ::looks
move Default steps ::motion
play Default Sound for Default Beats :: sound
broadcast Deault ::events
ask Default Text and wait :: sensing
(answer )=Default Text :: operators
set [Default v] to Default :: variables
add Default to [Default v] ::list
define Default
Default Text goes here:: custom
deck26
Scratcher
1000+ posts

Variables Keep On Saying "Infinity"

Just_ng wrote:

So… whats the use of using join?
Try this

Set up the following

when green flag clicked
set [var1 v] to [123456789012345678901234567890]
set [var2 v] to ((var1) + [0])
and see how these are displayed. Scratch treats the first as a text string and the second as a number because you've used a mathematical operator.

There's no need to use join if that's how you input your long strings of digits but you haven't actually said how this data is entered. If you're writing to a cloud variable that usually means building up the data from different values and if you want it as a text string you need to use join to combine the values.

If this still isn't clear you need to give us more infomation or, preferably, share your project.

Powered by DjangoBB