Discuss Scratch

trolley_explodes
Scratcher
100+ posts

instances of () in ()

(instances of () in ():: operators)
Support:
1.) BendyOl183

Last edited by trolley_explodes (Yesterday 16:10:18)

BendyOl183
Scratcher
500+ posts

instances of () in ()

What would this do?
trolley_explodes
Scratcher
100+ posts

instances of () in ()

BendyOl183 wrote:

What would this do?
If you have 4 e's in a string of letters like adwpigjpnavoitwetnweopajrintoweptkoawe it returns 4.
BendyOl183
Scratcher
500+ posts

instances of () in ()

trolley_explodes wrote:

BendyOl183 wrote:

What would this do?
If you have 4 e's in a string of letters like adwpigjpnavoitwetnweopajrintoweptkoawe it returns 4.
That sounds cool, I support

This could be used for stuff like checking how many characters you have typed which would be helpful in TTS projects, as each TTS block doesn't speak more than 100 characters, this would make it easier for people to check how many characters they have written without using a different website.
Zydrolic
Scratcher
1000+ posts

instances of () in ()

Workaround incase you'd want to make it in a custom block:
define instances of (letter) in (string)
set [cycle v] to [0]
set [output v] to [0]
repeat until <(cycle) > (length of (string))>
if <(letter (cycle) of (string)) contains (letter)?> then
change [output v] by [1]
end
change [cycle v] by [1]
end
(If you don't wanna recreate this in the editor for some reason, you can just backpack it here)

Last edited by Zydrolic (Yesterday 16:08:31)

trolley_explodes
Scratcher
100+ posts

instances of () in ()

Zydrolic wrote:

Workaround incase you'd want to make it in a custom block:
define instances of (letter) in (string)
set [cycle v] to [0]
set [output v] to [0]
repeat until <(cycle) > (length of (string))>
if <(letter (cycle) of (string)) contains (letter)?> then
change [output v] by [1]
end
change [cycle v] by [1]
end
That's pretty big, I think new scratchers would have a real hard time making this so…

Last edited by trolley_explodes (Yesterday 16:08:54)

Zydrolic
Scratcher
1000+ posts

instances of () in ()

trolley_explodes wrote:

(#6)
That's pretty big, I think new scratchers would have a real hard time making this so…
It's not that big, though? It's only 15 blocks - Most code is longer than that. Though I can see your point about a new scratcher having a hard time if they just… Don't think about cycling through the text for the count. (Not sure how I can put that any other way)

Last edited by Zydrolic (Yesterday 16:12:36)

unknown2467
Scratcher
100+ posts

instances of () in ()

I think this is a duplicate, but I can't find the original topic.
trolley_explodes
Scratcher
100+ posts

instances of () in ()

unknown2467 wrote:

I think this is a duplicate, but I can't find the original topic.
Then please don't post it until you're sure.
TheBaton
Scratcher
100+ posts

instances of () in ()

Hey, there is a better workaround to this so you can check for multi-character strings.

define instances of (string1) in (string2)
delete [all v] of [paste v]
delete [all v] of [parse v]
set [index v] to [0]
set [instances v] to [0]
set [cycle v] to [0]
repeat (length of (string2))
change [index v] by [1]
change [cycle v] by [1]
add (letter (index) of (string2)) to [paste v]
if < (cycle) > (length of (string1)) > then
delete [1] of [paste v]
set [cycle v] to [0]
end
if < (string1) = (paste) > then
change [instances v] by [1]
end
end

There is no “it would be too difficult for new users to implement” excuse here, or anywhere. Certainly, this block is a good idea. However, since the workarounds are plentiful and are easy to integrate, there is no reason to add it in. And if new users cannot deal with the fact that they are required to build something as such, that is an issue that does not fall to the Scratch Team to fix.
medians
Scratcher
1000+ posts

instances of () in ()

There could also be an equivalent for lists:
(# of [item] in [list v]::list)
TheBaton
Scratcher
100+ posts

instances of () in ()

medians wrote:

There could also be an equivalent for lists:
(# of [item] in [list v]::list)

This can also be worked around:

repeat until <not <[list v] contains [hello]>
delete (item # of [hello] in [list v]) of [list v]
change [instances v] by [1]
end

There may be a slight error, and an additional “change instances by -1” after the repeat loop, but it should work as you'd want it to.
trolley_explodes
Scratcher
100+ posts

instances of () in ()

TheBaton wrote:

-snip-
There is no “it would be too difficult for new users to implement” excuse here, or anywhere. Certainly, this block is a good idea. However, since the workarounds are plentiful and are easy to integrate, there is no reason to add it in. And if new users cannot deal with the fact that they are required to build something as such, that is an issue that does not fall to the Scratch Team to fix.
Go look at the list of rejected suggestions and find the 3d scratch section. The literal reason that they rejected it is because it was to complicated.
TheBaton
Scratcher
100+ posts

instances of () in ()

trolley_explodes wrote:

TheBaton wrote:

Go look at the list of rejected suggestions and find the 3d scratch section. The literal reason that they rejected it is because it was to complicated.

There's no sense in argument here, because I do believe this would be a cool block, but it's simply too easy to implement yourself. The reason 3D Scratch isn't a base feature is because what most would see as functional 3D engines, being something like Unity or Godot, have very complicated menus and windows which Scratch does not. 3D Scratch is not even remotely in proportion of complexity to counting the instances of a string in another. 3D Scratch's ambiguity really holds no validity to your suggestion, but I digress. You must think about the workarounds, and this block doesn't necessarily meet nor exceed the threshold of complexity required for the Scratch Team to go out of their way to make it. There is no project delay or congestion as a result of using a workaround as many have already shown. So, there is no reason to implement this block. No coding is beginner friendly. You just have to take baby steps. And once you've reached a certain “Scratch maturity”, you can handle any kind of project-making.

I hope you understand that this is in no way a personal attack or anything like that. I'm simply letting you know that you have to really weigh the importance of the block or extension. The Scratch Team's job is to take care and monitor the app, not add in random blocks to the community's every whim.

Last edited by TheBaton (Today 06:16:39)

medians
Scratcher
1000+ posts

instances of () in ()

TheBaton wrote:

medians wrote:

There could also be an equivalent for lists:
(# of [item] in [list v]::list)

This can also be worked around:

repeat until <not <[list v] contains [hello]>
delete (item # of [hello] in [list v]) of [list v]
change [instances v] by [1]
end

There may be a slight error, and an additional “change instances by -1” after the repeat loop, but it should work as you'd want it to.
I know about workarounds, but I feel like you should use another way so that items aren't deleted from the list like iterating over the list and checking. It could be like this:
define # of (string) in list
set [count v] to [0]
set [iteration v] to [0]
repeat (length of [list v])
change [iteration v] by (1)
if <(item (iteration) of [list v]) = (string)> then
change [count v] by (1)
end
end
Though, maybe you could replace the items with a specific item that isn't used in the project anywhere else instead of deleting, and then add:
repeat until <not <[list v] contains [unused]?>>
replace item (item # of [unused] in [list v]) of [list v] with [hello]
end

Powered by DjangoBB