Discuss Scratch

fyromaniac1
Scratcher
100+ posts

Is Letter, Number, or Symbol Block

Ever had a project that had to use only numbers/letters/symbols? You might have to do something like this:
when flag clicked
forever
if <(answer) = (1)
end
if <(answer) = (2)
end
if <(answer) = (3)
end
if <(answer) = (4)
end
if <(answer) = (5)
end
if <(answer) = (6)
end
etc.
Well, a good suggestion would be to have a block that detects if the string is a number, symbol, or letter, Like this!
([] is [number v])
([] is [letter v])
([] is [symbol v])
Here is an example of the new block in action:
When clicked
ask [give me a number!] and wait
if <(answer) is [number v]> then
say [That's a cool number!]
else
say [Not a number :(]
end
So basically, It is a Reporter block that would most likely be in the |Sensing| Section of the Block Palette.
If you say:
say ((3) is [number v)
then it will come out saying “True”.

This is my Idea, and please follow this Topic, and support!

Last edited by fyromaniac1 (Nov. 16, 2013 01:20:46)

ppettitt
Scratcher
100+ posts

Is Letter, Number, or Symbol Block

Support!
turkey3_test
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

You can have each symbol in a list (I.e. Numbers) and check of the list contains the symbol, so I don't support.
fyromaniac1
Scratcher
100+ posts

Is Letter, Number, or Symbol Block

turkey3 wrote:

You can have each symbol in a list (I.e. Numbers) and check of the list contains the symbol, so I don't support.
Well, the list can't have every number/symbol because first of all, there are TONS of symbols and an infinite number of numbers, so that list would be pretty long.
ProdigyZeta7
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

turkey3_test wrote:

You can have each symbol in a list (I.e. Numbers) and check of the list contains the symbol, so I don't support.
Yeah, but think about all the letters with diacritics

I'm supporting because I hate using alt + #### to make symbols in lists to detect the type of string.
mobluse
Scratcher
100+ posts

Is Letter, Number, or Symbol Block

This is already possible:
if <<(answer) = [0]> or <not <((answer) + (1)) = [1]>>> then
say [is number] for (2) secs
else
say [is string] for (2) secs
end

This solution comes from http://mv.ezproxy.com.ezproxyberklee.flo.org/wiki/String#String_or_Number.3F
But I used De Morgan's laws to change it from “isString” to “isNumber”.

It would be better if procedures could return a value, i.e. one should have functions. To have a lot of new boolean functions would clutter the GUI for beginners – especially when this could be solved by a general solution (i.e. functions).

No support!
Rumanti
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

mobluse wrote:

This is already possible:
if <<(answer) = [0]> or <not <((answer) + (1)) = [1]>>> then
say [is number] for (2) secs
else
say [is string] for (2) secs
end

No support!

+1 Awesome. But what he suggests is pretty handy, and simple. New Scratchers could use it pretty quickly. So I support him too. +1
1234abcdcba4321
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

But you can already DO it!
(nah, why not.)

As a workaround for numbers, you could do
if <<(...) < [9]> or <(...) > [-9]>> then
end
cobraguy
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

Even after looking at the workarounds, I support! It would be faster than using the workarounds.

EDIT: Hold on, what would a mixture of number, letters, and symbols count as?

Last edited by cobraguy (Nov. 18, 2013 00:09:57)

fyromaniac1
Scratcher
100+ posts

Is Letter, Number, or Symbol Block

Everything: !@#$%^&*()-=_+`~,./<>?;':"\{}| (Including Alt codes such as Alt 1)
Letters: ABCDEFGHIJKLMNOPQRSTUVUXYZ
Numbers 12345678910121314151617181920 etc. etc. etc.
ProdigyZeta7
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

cobraguy wrote:

Hold on, what would a mixture of number, letters, and symbols count as?
A string, duh.
AonymousGuy
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

I support, although I can't think right now of a place I would need to use it…

Maybe in an input situation that required a number (such as a shop in an RPG game where you specify the amount of items)
cobraguy
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

ProdigyZeta7 wrote:

cobraguy wrote:

Hold on, what would a mixture of number, letters, and symbols count as?
A string, duh.
EDIT: Nevermind, I figured out how any problems could be fixed.

Last edited by cobraguy (Nov. 18, 2013 14:27:44)

liam48D
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

This is great! But, I can't remember the last time ST added a real block, since 2.0.

+1 Support!
jTron
Scratcher
100+ posts

Is Letter, Number, or Symbol Block

For the most part, I support. Other types of characters (or even word, etc.) could be added.
Also, a better workaround - put the options in a list and use the <[… v] contains [thing]> block.
Edit: already mentioned, never mind :)

Lastly, a protip: use
([] is [number v] :: operators)
to change the type of block:
([] is [number v] :: operators)

when this sprite clicked
if <(answer) is [number v] :: operators> then
... :: more
end

Last edited by jTron (March 10, 2014 18:22:50)

educationiskey
New Scratcher
1 post

Is Letter, Number, or Symbol Block

I totally agree. I have used workarounds, but this would be better. (Before I saw some of the scripts here, I was doing If Answer = 1 or Answer = 2 etc. )
stickfiregames
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

I definitely support a block for testing numbers (even though there is a workaround).


The problem with the letter one is you get into technicalities about what is and isn't a letter. For example:
<[A] is a [letter v]? :: operators> // yes
<[Ж] is a [letter v]? :: operators> // yes
<[ݭ] is a [letter v]? :: operators> // yes
<[ス] is a [letter v]? :: operators> // technically it isn't, but it's used in the same way as one
<[人] is a [letter v]? :: operators> // even more ambiguous, since it represents a meaning not a sound, but is still used in writing
Of course, you could have “is a Latin letter” but that wouldn't be so useful in other languages.


Same for the symbol one, since it is basically “anything that is not a letter or number”.
robosnakejr
Scratcher
1000+ posts

Is Letter, Number, or Symbol Block

Support
CodingJam
Scratcher
17 posts

Is Letter, Number, or Symbol Block

This doesn't work

Last edited by CodingJam (Dec. 28, 2022 09:43:19)

Griffenlover
Scratcher
100 posts

Is Letter, Number, or Symbol Block


CodingJam wrote:

You could make a sprite with loads of costumes all named:
Other
as the first costume
al
bl
cl
dl
for all the letters
:s
's
#s
,s
for all the symbols.
Then you could make a block called letter, number, or symbol which looks like:
define letter, number, or symbol(char)
switch costume to [other v]
switch costume to (char)
if <(costume #) = [1]> then
set [type v] to [number]
end
if <(letter (length of (char)) of (char)) = [l]> then
set [type v] to [letter]
end
if <(letter (length of (char)) of (char)) = [s]> then
set [type v] to [symbol]
end
please dont necropost, the last post was 2 years ago

Powered by DjangoBB