Discuss Scratch

Seth_Zaw
Scratcher
100+ posts

A block where you can et a letter off a word

It would look like this:
(letter # of [a] in [apple] :: operators)
It would act similar to the
(item # of [thing] in [list v] :: list)
, except it is used for words instead.
coder2045
Scratcher
1000+ posts

A block where you can et a letter off a word

What happens in these cases?

(letter # of [a] in [abcabb]::operators)
(letter # of [z] in [apple]::operators)
(letter # of [ad] in [fegade]::operators)
(letter # of [] in [abc123]::operators)
Seth_Zaw
Scratcher
100+ posts

A block where you can et a letter off a word

coder2045 wrote:

What happens in these cases?

(letter # of [a] in [abcabb]::operators)
(letter # of [z] in [apple]::operators)
(letter # of [ad] in [fegade]::operators)
(letter # of [] in [abc123]::operators)
1. It always reports the first case, so it reports 1
2. If the word doesn't contain the letter, then it reports 0.
3. It will report 4, since “ad” is right after G, which is the third letter in the word.
4. Same as 2
DoNotFoIIowMe
Scratcher
100+ posts

A block where you can et a letter off a word

Below, I created a system that loops through your text until it reaches the letter you want and then sets the output to the variable that looped through since it will have the correct number in it.

when green flag clicked
set [text v] to [Your text...]
set [i v] to [0]
repeat (length of (text))
change [i v] by (1)
if <(letter (i) of (text)) = [y]> then // replace the y with your letter
set [output v] to (i) // this variable has the answer
stop [this script v]
end
end

Is this what you wanted?

Last edited by DoNotFoIIowMe (Nov. 19, 2019 16:11:06)

Seth_Zaw
Scratcher
100+ posts

A block where you can et a letter off a word

DoNotFoIIowMe wrote:

Below, I created a system that loops through your text until it reaches the letter you want and then sets the output to the variable that looped through since it will have the correct number in it.

when green flag clicked
set [text v] to [Your text...]
set [i v] to [0]
if <(text) contains [y]? :: operators> then
repeat (length of (text))
change [i v] by (1)
if <(letter (i) of (text)) = [y]> then // replace the y with your letter
set [output v] to (i) // this variable has the answer
stop [this script v]
end
end
else
set [i v] to [0]
end

Is this what you wanted?
Not exactly. I said that it will report 0 if it doesn't contain the letter.
DoNotFoIIowMe
Scratcher
100+ posts

A block where you can et a letter off a word

Seth_Zaw wrote:

-snip-
Not exactly. I said that it will report 0 if it doesn't contain the letter.

Wrong - the “i” variable after the else needs to switched with “output”.
qucchia
Scratcher
100+ posts

A block where you can et a letter off a word

DoNotFollowMe's code converted into a custom block:

define letter # of (letter) in (string)
set [i v] to [0]
if <(string) contains (letter)? :: operators> then
repeat (length of (string))
change [i v] by (1)
if <(letter (i) of (string)) = (letter)> then
set [output v] to (i)
stop [this script v]
end
end
else
set [output v] to [0]
end

The result is in the output variable.
45afc4td
Scratcher
100+ posts

A block where you can et a letter off a word

I suppose

(letter # of [s] in [\Scratchblocks] :: operators)

would return 1 as the Scratch Team does not like case-sensitivity.

Last edited by 45afc4td (Nov. 26, 2019 16:47:20)

FloatingMuffins
Scratcher
1000+ posts

A block where you can et a letter off a word

Support. Could be a useful block.
Botcho_Otkho
Scratcher
1000+ posts

A block where you can et a letter off a word

45afc4td wrote:

as the Scratch Team does not like case-sensitivity.
That doesn't look like a serious motivation to me. I think it's just a design choice or a way of making things simpler, not an liking or a disliking towards one specific function. But I assume the output of the block would still be 1.
Nambaseking01
Scratcher
1000+ posts

A block where you can et a letter off a word

qucchia wrote:

DoNotFollowMe's code converted into a custom block:

define letter # of (letter) in (string)
set [i v] to [0]
if <(string) contains (letter)? :: operators> then
repeat (length of (string))
change [i v] by (1)
if <(letter (i) of (string)) = (letter)> then
set [output v] to (i)
stop [this script v]
end
end
else
set [output v] to [0]
end

The result is in the output variable.

DoNotFoIIowMe is technically me (read their siggy) so thanks for creating the custom block.
LuckyLucky7
Scratcher
1000+ posts

A block where you can et a letter off a word

No support. There is a simple workaround:

(letter () of (item ( v) of [list v] :: list))
LastContinue
Scratcher
500+ posts

A block where you can et a letter off a word

LuckyLucky7 wrote:

No support. There is a simple workaround:

(letter () of (item ( v) of [list v] :: list))
That's not what OP is asking but yes that does something at least.
Seth_Zaw
Scratcher
100+ posts

A block where you can et a letter off a word

LuckyLucky7 wrote:

No support. There is a simple workaround:

(letter () of (item ( v) of [list v] :: list))
That workaround is far beyond the correct one.
AFNNetworkK12
Scratcher
1000+ posts

A block where you can et a letter off a word

There are workarounds, so I am going for no support.
Also, you could also always make a extension and use it on ScratchX (enter at your own risk!)
Nambaseking01
Scratcher
1000+ posts

A block where you can et a letter off a word

AFNNetworkK12 wrote:

There are workarounds, so I am going for no support.
Also, you could also always make a extension and use it on ScratchX (enter at your own risk!)

ScratchX is shutting down next year because it runs on Flash.

Nammy
Vanilla2011
Scratcher
500+ posts

A block where you can et a letter off a word

Seth_Zaw
Scratcher
100+ posts

A block where you can et a letter off a word

Vanilla2011 wrote:

Duplicate
Oh

Powered by DjangoBB