Discuss Scratch
- PhoenixAndStuf
-
62 posts
Varibles having imaginary numbers
Ok, so from what I can gather, you want to be able to tell the program that a variable is just a number and nothing else?
I mean, this boolean checks if any variable is a number if that's what you are looking for.
also, please stop harassing me just 'cause I forgot what an irrational number was. :P
also also, please stop fact-checking the OP because a zillion people already have. the writer of the OP gets it.
I mean, this boolean checks if any variable is a number if that's what you are looking for.
if <(input) = ((input) * (1))> then
Code that runs if it is a number :: sensing
else
Code that runs if it's not a number :: sensing
end
also, please stop harassing me just 'cause I forgot what an irrational number was. :P
also also, please stop fact-checking the OP because a zillion people already have. the writer of the OP gets it.
Last edited by PhoenixAndStuf (Nov. 26, 2022 18:10:05)
- Minecraft_Master3964
-
500+ posts
Varibles having imaginary numbers
No no,
thats not what im talking about.
for example
myVariable = *imaginary number*
the *imaginary number* could be any number, it doesnt matter, its imaginary,
its basically telling the program that this is just a number.
You guys dont get it
Are you saying you want a block that tells the program a variable is a number, but you don't know what the number is?
So, it could be 1, or 500, or even 1,000,000, but you only know it's a number right now.
Like this?
set data type of [variable v] to [number v] ::variables
- MushroomGamesETC
-
13 posts
Varibles having imaginary numbers
No you guys still dont get it >
.
What I mean by “imaginary numbers” is by tellling the program this could be ANY number.
dont throw “the square root of negative number” at me.
I know that its a sqrt of negative number.
what I mean was telling the program that this could be ANY number.
for example:
telling the program to find sprites named (cookie + *imaginary number*)
It could find, cookie1, cookie2, cookie3 and other sprites named cookie with *imaginary number*
Do you get it now?

What I mean by “imaginary numbers” is by tellling the program this could be ANY number.
dont throw “the square root of negative number” at me.
I know that its a sqrt of negative number.
what I mean was telling the program that this could be ANY number.
for example:
telling the program to find sprites named (cookie + *imaginary number*)
It could find, cookie1, cookie2, cookie3 and other sprites named cookie with *imaginary number*
when green flag clicked
if <<touching [((cookie) + (J)) v] ?>> then
move (10) steps
end
Do you get it now?
- PkmnQ
-
1000+ posts
Varibles having imaginary numbers
Ah, so a replacement for any number. I think a better topic name would be “placeholder number”. I have a question: What would this do? No you guys still dont get it >.
What I mean by “imaginary numbers” is by tellling the program this could be ANY number.
dont throw “the square root of negative number” at me.
I know that its a sqrt of negative number.
what I mean was telling the program that this could be ANY number.
for example:
telling the program to find sprites named (cookie + *imaginary number*)
It could find, cookie1, cookie2, cookie3 and other sprites named cookie with *imaginary number*when green flag clicked
if <<touching [((cookie) + (J)) v] ?>> then
move (10) steps
end
Do you get it now?
if <(placeholder number :: custom-arg) = [1]> thenActually, more importantly, what would this do?
say [placeholder number is 1]
else
say [placeholder number is not 1]
end
say (placeholder number :: custom-arg)
- PhoenixAndStuf
-
62 posts
Varibles having imaginary numbers
So what you are saying is that there should be some kind of number placeholder to account for any number?
So instead of writing…
You can write…
Where J accounts for all of the numbers at the end of the string, “sprite”.
I think that's a cool idea!
So instead of writing…
if <<touching [sprite1 v] ?> or <<touching [sprite2 v] ?> or <touching [sprite3 v] ?>>> then
...
end
You can write…
if <touching (join [sprite] (J :: #ee454e)) > then
...
end
Where J accounts for all of the numbers at the end of the string, “sprite”.
I think that's a cool idea!
Last edited by PhoenixAndStuf (Nov. 27, 2022 18:55:25)
- MushroomGamesETC
-
13 posts
Varibles having imaginary numbers
How would that work? Foo isnt an placeholder, it can only be a specofic number like 1, or 2.
I want the program to know that Foo could be ANY number.
.
I want the program to know that Foo could be ANY number.
if <touching (join [sprite] (foo)) ?> thenPlease how? I need thiis for a Mario game
...
end

Last edited by MushroomGamesETC (Nov. 27, 2022 19:33:10)
- PsychicAura
-
100+ posts
Varibles having imaginary numbers
Ohhhhhhhh I get it…
What you're is basically that it could be anything, but only useful in “if” statements.
But can't you just keep doing the “or” boolean?
What you're is basically that it could be anything, but only useful in “if” statements.
But can't you just keep doing the “or” boolean?
- PhoenixAndStuf
-
62 posts
Varibles having imaginary numbers
I want the program to know that Foo could be ANY number.
What you can do first is to make foo a list variable and add the numbers that you need. The following code should do the trick.
when green flag clicked
delete all of [foo v] :: list
repeat (20) // Repeat as many numbers as you need in the list.
add (length of [foo v]) to [foo v]
end
Then, you have to use a hidden block called the “item any” reporter.
(item [any] of [foo v] :: list)
To get this special block, copy and paste the word “any” into the normal “item” reporter. You can't type it normally.
There you have it, a reporter that can represent any number that is in your list.
Example:
when green flag clicked
forever
... // Game code...
if <touching (join [sprite] (item [any] of [list v] :: list)) ?> then
play sound [tada! v]
end
end
Please let me know if this works, I only did 1 test with it. The block is a bit broken and very slow which is the downside to using it.
Last edited by PhoenixAndStuf (Nov. 27, 2022 22:13:43)
- MushroomGamesETC
-
13 posts
Varibles having imaginary numbers
Ill test this out!
Maybe this is an answer.
Maybe this is an answer.
if <touching (join [sprite] (item [any] of [foo v] :: list)) ?> then
...
end
Last edited by MushroomGamesETC (Nov. 27, 2022 23:23:17)
- MushroomGamesETC
-
13 posts
Varibles having imaginary numbers
Okay so, this works for me.
The list is in a fixed range of numbers.
It isnt exactly an imagnary number but more like a range number.
But thats good enough
.
Thank you for your participation and help
.
when green flag clicked
forever
if <touching (join [brick-blocks] (item [any] of [numbers v] :: list)) ?> then
...
end
end
The list is in a fixed range of numbers.
It isnt exactly an imagnary number but more like a range number.
But thats good enough

Thank you for your participation and help

Last edited by MushroomGamesETC (Nov. 27, 2022 23:23:52)
- PkmnQ
-
1000+ posts
Varibles having imaginary numbers
Ok, I knew about “item last” and “item random”, but this is just pure magic. Is there an “item all” version?(item [any] of [foo v] :: list)
To get this special block, copy and paste the word “any” into the normal “item” reporter. You can't type it normally.
- portalpower
-
1000+ posts
Varibles having imaginary numbers
Why? What problem would a scratcher run into when making a typical scratch project that can be solved by this?
- MushroomGamesETC
-
13 posts
Varibles having imaginary numbers
Ok, I knew about “item last” and “item random”, but this is just pure magic. Is there an “item all” version?(item [any] of [foo v] :: list)
To get this special block, copy and paste the word “any” into the normal “item” reporter. You can't type it normally.
I dont know. however
(item [all] of [list v] :: list)
is a pure life saver. reccomended
- da-maker
-
100+ posts
Varibles having imaginary numbers
I think “item any” is just equivalent to “item random”. This is likely why it's “a bit broken” and “slow”; it reports items from the list at random.Ok, I knew about “item last” and “item random”, but this is just pure magic. Is there an “item all” version?(item [any] of [foo v] :: list)
To get this special block, copy and paste the word “any” into the normal “item” reporter. You can't type it normally.
- MushroomGamesETC
-
13 posts
Varibles having imaginary numbers
I think “item any” is just equivalent to “item random”. This is likely why it's “a bit broken” and “slow”; it reports items from the list at random.Ok, I knew about “item last” and “item random”, but this is just pure magic. Is there an “item all” version?(item [any] of [foo v] :: list)
To get this special block, copy and paste the word “any” into the normal “item” reporter. You can't type it normally.
So do you have a better suggestion?
How about range numbers?
Like instead of telling the program that this could be ANY number,
its telling the number that it could be a number from 1-10.
- PhoenixAndStuf
-
62 posts
Varibles having imaginary numbers
Like instead of telling the program that this could be ANY number,
its telling the number that it could be a number from 1-10.
I don't think that this suggestion is really possible yet, all you have is the relatively slow workaround. You could just use “or” statements.
if <<touching [sprite1 v] ?> or <<touching [sprite2 v] ?> or <<touching [sprite3 v] ?> or <<touching [sprite4 v] ?> or <touching [sprite5 v] ?>>>>> then
...
end
Semi-support to add a “J” variable. But what would this…
say (J)
do?
Last edited by PhoenixAndStuf (Nov. 28, 2022 15:30:39)
- coder2045
-
1000+ posts
Varibles having imaginary numbers
You can't make words numbers. That makes no logical sense. No no,
thats not what im talking about.
for example
myVariable = *imaginary number*
the *imaginary number* could be any number, it doesnt matter, its imaginary,
its basically telling the program that this is just a number.
You guys dont get it
- 7salad3salad
-
1000+ posts
Varibles having imaginary numbers
POV: VariablesYou can't make words numbers. That makes no logical sense. No no,
thats not what im talking about.
for example
myVariable = *imaginary number*
the *imaginary number* could be any number, it doesnt matter, its imaginary,
its basically telling the program that this is just a number.
You guys dont get it
- PkmnQ
-
1000+ posts
Varibles having imaginary numbers
I just realized that this is actually impossible to implement, as in the laws of math prevent this, or we would've solved lots of important unsolved math problems by now.
In other programming languages, you'd use a list here and combine it with an actual “item any” thing that isn't just “item random” in disguise (in Python it's the any() function) or implement it yourself. With how Scratch works, I'm not really sure if that could fit here. In Snap! it definitely could (did I italicize that correctly?), but not in Scratch.
For small numbers, it's best to just manually do this:
In other programming languages, you'd use a list here and combine it with an actual “item any” thing that isn't just “item random” in disguise (in Python it's the any() function) or implement it yourself. With how Scratch works, I'm not really sure if that could fit here. In Snap! it definitely could (did I italicize that correctly?), but not in Scratch.
For small numbers, it's best to just manually do this:
<<<touching [sprite1 v] ?> or <touching [sprite2 v] ?>> or <touching [sprite3 v] ?>>But if you have hundreds, you can put them in a list and do this:
set [touching any? v] to [no]
set [item v] to [1]
repeat until <<(touching any?) = [yes]> or <(item) > (length of [sprites v])>>
if <touching (item (item) of [sprites v])> then
set [touching any? v] to [yes]
end
change [item v] by (1)
end
- ajskateboarder
-
1000+ posts
Varibles having imaginary numbers
I thought this was supposed to be like a type hint in Python where you can explicitly state a variable as an integer:
But it seems the OP wants an actual placeholder variable where (almost) any number can be used. This probably isn't performant at all since all numbers from 0 to the 64-bit number limit can be calculated, and using this in an if statement would take far too long because every number to the 64-bit limit has to be checked inside the statement. If you don't know what the 64 bit number limit (signed) is, it's 9,223,372,036,854,775,807. It should be able to iterate to the 64-bit limit since that also happens to be the number limit Scratch uses for variables.
Example of checking multiple sprites' costume number:
Without the context of what block this is being used with, this will enumerate over all numbers in range of the 64-bit limit just to find a matching condition. That's too slow. If the placeholder were to understand the context however, it would only iterate over the number of sprites in the project that start with “sprite”.
To do that, fundamental changes would have to be made to the Scratch AST since the placeholder block not only has to be interpreted by the VM, but now has to check parent blocks for context to make sure it doesn't have to iterate over the 64-bit limit. This would add on a lot of extra time spent interpreting the block, especially when it's being used many times across a Scratch project.
So for mathematical purposes and for sake of keeping Scratch projects optimized, I don't support.
set data type of [variable v] to [number v] ::variables
But it seems the OP wants an actual placeholder variable where (almost) any number can be used. This probably isn't performant at all since all numbers from 0 to the 64-bit number limit can be calculated, and using this in an if statement would take far too long because every number to the 64-bit limit has to be checked inside the statement. If you don't know what the 64 bit number limit (signed) is, it's 9,223,372,036,854,775,807. It should be able to iterate to the 64-bit limit since that also happens to be the number limit Scratch uses for variables.
Example of checking multiple sprites' costume number:
if <([costume # v] of (join [sprite] (placeholder ::custom)) ::sensing) = [1]> then
say [Hello] for (2) seconds ::looks
end
Without the context of what block this is being used with, this will enumerate over all numbers in range of the 64-bit limit just to find a matching condition. That's too slow. If the placeholder were to understand the context however, it would only iterate over the number of sprites in the project that start with “sprite”.
To do that, fundamental changes would have to be made to the Scratch AST since the placeholder block not only has to be interpreted by the VM, but now has to check parent blocks for context to make sure it doesn't have to iterate over the 64-bit limit. This would add on a lot of extra time spent interpreting the block, especially when it's being used many times across a Scratch project.
So for mathematical purposes and for sake of keeping Scratch projects optimized, I don't support.