Discuss Scratch

gamer270
Scratcher
18 posts

split block

I want a block like this to be added like
(split (scratch) at character(character to split at))
you could put it inside a list item select block like this
(item (1 v) of (split (scratch) at character(character to split at))) 
If
(character to split at)
was “a” the two items in the list would be “scr” and “tch”
AonymousGuy
Scratcher
1000+ posts

split block

gamer270 wrote:

I want a block like this to be added like
(split [scratch] at character [a]) //category=operators
That block looks better.

Anyways, I think this could be interesting, but would have to handle lists differently (as they are handled in BYOB) so I think that there needs to be a different way to make this block if it is going to be implemented.
1234abcdcba4321
Scratcher
1000+ posts

split block

no support, already workaroundable.
Rex208
Scratcher
500+ posts

split block

This is a block idea I had.
The block would look something like this:

(Section () of [] split by []) //category=operators

What it would do:

1. The block would split the first string wherever the second string appeared in it.
2. Then it would number the sections the second string was split up into.
3. Then it would count until it found a section with the same number as the number that was used as the number input. That would be the output.

e.g:
(Section (2) of [Hi, how are you today, Scratch cat?] split by [,]) //category=operators

1. “Hi, how are you today, Scratch cat?” would be split up into “Hi”, “ how are you today”, and “ Scratch cat?”
2. The sections would be numbered.
“Hi” is number 1.
“ how are you today” is number 2.
“ Scratch cat?” is number 3.
3. The block wants section 2, or “ how are you today”. That then becomes the output.

Possible uses:

Storing lists through cloud data, storing matrices or maybe even 3d matrices easily, storing multiple variables all in one variable, making import/export saved game data buttons easier…

powercon5
Scratcher
1000+ posts

split block

cool idea
little_kitten
Scratcher
500+ posts

split block

Support!
   ._. ::sound
._.
._. ::list
._. ::control
._. ::operators
._. ::pen
._. ::sensing
._. ::motion
._. ::looks
gregory9
Scratcher
100+ posts

split block

Support. This is basically
$result = explode(“Hi, how are you today, Scratch cat?”, “,”);
in PHP then getting the second item of result (“Scratch cat?”)
cwrivera99
Scratcher
500+ posts

split block

Workaround! I have a project about this. It shows you how to encode an entire list into a variable. I call the encoding method “separated strings” becase it separates each item on the list with a predefined character. Here's the workaround for the block you're proposing.
define Find Item (Item) of (String) with Separator (Separator)
set [Counter v] to [0]
repeat ((Item) - (1))
repeat until <(letter (Counter) of (String)) = (Separator)>
change [Counter v] by (1)
end
change [Counter v] by (1)
end
set [Output v] to []
repeat until <(letter (Counter) of (String)) = (Separator)>
set [Output v] to (join (Output) (letter (Counter) of (String)))
change [Counter v] by (1)
The “Output” variable is your answer.

Last edited by cwrivera99 (Nov. 22, 2014 20:32:13)

rollercoasterfan
Scratcher
1000+ posts

split block

Support!
sithsiri
Scratcher
100+ posts

split block

support
Cream_E_Cookie
Scratcher
1000+ posts

split block

Support, but make it better
Zekrom01
Scratcher
1000+ posts

split block

support
DaSpudLord
Scratcher
1000+ posts

split block

No support, workaroundable.

Also, there's a duplicate out there somewhere.

Last edited by DaSpudLord (Aug. 31, 2015 16:26:48)

Cream_E_Cookie
Scratcher
1000+ posts

split block

DaSpudLord wrote:

No support, workaroundable.

Also, there's a duplicate out there somewhere.
Actually, the thread that you are probably thinking of is the duplicate.

DaSpudLord wrote:

No support, workaroundable.

Also, there's a duplicate out there somewhere.
Anything is workaroundable.
(well, you g et my point)
DaSpudLord
Scratcher
1000+ posts

split block

Cream_E_Cookie wrote:

DaSpudLord wrote:

No support, workaroundable.

Also, there's a duplicate out there somewhere.
Anything is workaroundable.
(well, you g et my point)
Is this workaroundable?
create file [] at []::custom
Because if so, I'd love to hear the workaround. (Seriously, I would really like this.)

Last edited by DaSpudLord (Aug. 31, 2015 17:24:58)

Zro716
Scratcher
1000+ posts

split block

The thing is the interpreter was not built to report lists as themselves, they get cast to strings. I would totally love a built-in split function to complement the join block (really bugging me a lot) and speed up many of my operations and save myself a few variables and debugging headaches… Though, I prefer that the split function, due to the nature of the interpreter, be a list stack block

split [hello, world!] by [space v] into [list v] ::list // where [space v] includes all characters on a standard keyboard
split [hello, world!] by [each letter v] into [list v] ::list // and includes this option too
If need be, the delimiter input can take anything so that more complicated splittings may be used.

Last edited by Zro716 (Aug. 31, 2015 17:27:51)

DaSpudLord
Scratcher
1000+ posts

split block

Zro716 wrote:

The thing is the interpreter was not built to report lists as themselves, they get cast to strings. I would totally love a built-in split function to complement the join block (really bugging me a lot) and speed up many of my operations and save myself a few variables and debugging headaches… Though, I prefer that the split function, due to the nature of the interpreter, be a list stack block

split [hello, world!] by [space v] into [list v] ::list // where [space v] includes all characters on a standard keyboard
split [hello, world!] by [each letter v] into [list v] ::list // and includes this option too
If need be, the delimiter input can take anything so that more complicated splittings may be used.
Actually, if removed, the
(join [][])
block would not have a workaround. Sure, you could use a list with the
(list::list)
reporter, but then there would be a space between each joined string, so… not a real workaround. But a split block does have a workaround.

Last edited by DaSpudLord (Aug. 31, 2015 17:34:32)

Zro716
Scratcher
1000+ posts

split block

DaSpudLord wrote:

Actually, if removed, the
(join [][])
block would not have a workaround. Sure, you could use a list with the
(list::list)
reporter, but then there would be a space between each joined string, so… not a real workaround. But a split block does have a workaround.
you don't have enough experience to appreciate the benefit of the split function. Especially in scratch where it is required to hack the JSON to fully utilize a custom script for splitting a string into a list. And hacking =/= valid workaround.
split [hello world] by [ ] into [list v]
/* have to hack the custom block procDef and call blocks to be able ::grey
to specify an available list without having to type it in every time */ ::grey
define split (string) by (splitter) into (list)
delete (all v) of (list) // have to hack the list blocks
set [split_substr v] to []
set [split_i v] to [0]
if <(splitter) = []> then // empty splitter means split by each letter
repeat (length of (string))
change [split_i v] by (1)
add (letter (split_i) of (string)) to (list)
end
else
repeat (length of (string))
change [split_i v] by (1)
set [split_chr v] to (letter (split_i) of (string))
if <(split_chr) = (splitter)> then
add (split_substr) to (list)
set [split_substr v] to []
else
set [split_substr v] to (join (split_substr)(split_chr))
end
end
if <not <(split_substr) = []>> then // leave no substring unadded
add (split_substr) to (list)
end
end

Last edited by Zro716 (Aug. 31, 2015 18:10:32)

Cream_E_Cookie
Scratcher
1000+ posts

split block

DaSpudLord wrote:

Cream_E_Cookie wrote:

DaSpudLord wrote:

No support, workaroundable.

Also, there's a duplicate out there somewhere.
Anything is workaroundable.
(well, you g et my point)
Is this workaroundable?
create file [] at []::custom
Because if so, I'd love to hear the workaround. (Seriously, I would really like this.)
I mean what exist's in scratch.
DaSpudLord
Scratcher
1000+ posts

split block

Cream_E_Cookie wrote:

DaSpudLord wrote:

...
I mean what exist's in scratch.
So this is workaroundable?
turn video [on v]

Zro716 wrote:

you don't have enough experience to appreciate the benefit of the split function.
No, but I have enough wisdom to understand the benefit of not having the split function-
  1. It could be confusing to inexperienced scratchers. Considering Scratch revolves around new scratchers, this is a stronger reason than some might realize.
  2. Forcing inexpereinced scratchers to come up with the workaround allows for a learning experience. It offers a chance to put their skills to the test in a problem-solving application. If they fail, then they can look up the answer and figure out how it works, so that next time they might succeed. Scratch revolves around teaching scratchers how to program and, more importantly, how to make stuff for themselves instead of being handed workarounds.
  3. Again, this is also a learning experience for skilled Scratchers. Without the block, you guys are forced to create the workaround. Whenever the workaround doesn't work they way you need it to for your project, that's another learning experience as you guys must test your brains to make the workaround work for you instead of having a workaround that doesn't work.
  4. Tired of programming being too simple? Then leave. Scratch is not about the skilled scratchers. It is not about you and me. It is for the unskilled scratchers to learn. Our purpose on this site is to create projects to act as guides that teach others how to do stuff that they might not know how to do. Stop trying to take Scratch and make it for you and the other skilled Scratchers. Instead, start thinking about the little guys for once.

Powered by DjangoBB