Discuss Scratch
- Greg8128
-
500+ posts
split blocks
Yes, all correct. and..They would report this: Nice, as long as it doesn't crash if it sees these:(section [3] of split [a.b] on character [.]::operators) // sections 3 and up do not exist
(section [1] of split [a.b] on character [Q]::operators) // that character is not in the input
(section [1] of split [a.b.c] on character [.]::operators) // multiple of that character are in the input
(section [1] of split [a.b] on character [ab]::operators) // this does not need an explanation.(section (3) of split [a.b] on character [.]::operators) // would report an empty stringAnd here's some extras to help you understand better:
(section (1) of split [a.b] on character [Q]::operators) // would report "a.b"
(section (1) of split [a.b.c] on character [.]::operators) // would report "a"
(section (1) of split [a.b] on character [ab]::operators) // would report "a.b"(section (1) of split [a.ab.b] on character [ab]::operators) // would report "a."
(section (2) of split [a.ab.b] on character [.]::operators) // would report "ab"actually, i just seemed to think of another workaround. sorry @Greg8128 but i think i will remove the stack block. Nice, as long as it doesn't crash if it sees these:(section [3] of split [a.b] on character [.]::operators) // sections 3 and up do not existAlso, the stack block, if this reporter were to be made, would have an obvious workaround like this:
(section [1] of split [a.b] on character [Q]::operators) // that character is not in the input
(section [1] of split [a.b.c] on character [.]::operators) // multiple of that character are in the input
(section [1] of split [a.b] on character [ab]::operators) // this does not need an explanation.add (section [] of split [] on character []::operators) to [list v]::list
Lastly, I think that this is a little too advanced for a website geared toward eight year olds. but then again:([abs v] of ())
Thanks for all the support and suggestions.set [ v] to []
repeat (length of [])
change [ v] by (1)
add (section (::variables) of split [text] on character [ ]::operators) to [list v]
end
the difference is that the workaround is forced to parse the string once for each section while my suggested block would have needed only one pass total. Say for example that you have 10000 numbers separated by semicolons. Even taking into account that the (section of split block) could stop parsing once it reaches the needed section, and disregarding the fact that Scratch code runs slower than JS code, the workaround would take roughly 5000 times longer to accomplish the same task.
Then again this is a somewhat niche use case so it might not be worth adding.
- cwkavery46304
-
29 posts
split blocks
I'm not sure.. we don't want to ask for too muchmitdk I would now like these 2 blocks to be added(section() of split[] on character[]::operators)and:split [] by [] and add to [list v]::operatorscredit to Greg8128 for this idea(as you can see in the posts above)
maybe they should move some of the opperators blocks to a new section called ‘text’ that would also have your split blocks.
good point mitdk.
- MartianSoil
-
100+ posts
split blocks
I don’t know if this has been mentioned yet, but what if you did
That would mess it up, which would it report. I assume the first one, but I feel like this would be better if it actually reported on the character number, like this:
When you click the last input it would bring up the number keypad that is used in other operator blocks such as
EDIT: Fixed Scratchblocks. Sorry that the emojis messed up script.
(section(1) of split[0244726382346234890] on character[8]::operators)
That would mess it up, which would it report. I assume the first one, but I feel like this would be better if it actually reported on the character number, like this:
(section() of split[] on character number[]::operators)
When you click the last input it would bring up the number keypad that is used in other operator blocks such as
((0) - (0))
EDIT: Fixed Scratchblocks. Sorry that the emojis messed up script.
Last edited by MartianSoil (Oct. 20, 2020 12:59:24)
- -CloudGate-
-
1000+ posts
split blocks
there is a pretty easy workaround, and most people who need this block will find it easy to make
- mitdk
-
1000+ posts
split blocks
Multiple chars being split has been mentioned before: I don’t know if this has been mentioned yet, but what if you did
(section(1) of split on character:perators)
That would mess it up, which would it report. I assume the first one, but I feel like this would be better if it actually reported on the character number, like this:
(section() of split on character number:perators)
When you click the last input it would bring up the number keypad that is used in other operator blocks such as((0) - (0))
If there are multiple of 1 character (say 2 periods) then you would get 3 sections. As for your other question, I got this idea from python, with the function
split(num, .)
In python, the split character disappears. I would go with that.
- PkmnQ
-
1000+ posts
split blocks
Does the easy workaround also work with multiple characters? there is a pretty easy workaround, and most people who need this block will find it easy to make
- MartianSoil
-
100+ posts
split blocks
I believe if you made a costume block that calculate which letter it was and what letter you want. I would make with scratchblocks, but it was getting to complicated, so I will put it in a project.
- cwkavery46304
-
29 posts
split blocks
we could make it so that it did not allow you to type a decimal point. I don’t know if this has been mentioned yet, but what if you did(section(1) of split[0244726382346234890] on character[8]::operators)
That would mess it up, which would it report. I assume the first one, but I feel like this would be better if it actually reported on the character number, like this:(section() of split[] on character number[]::operators)
When you click the last input it would bring up the number keypad that is used in other operator blocks such as((0) - (0))
EDIT: Fixed Scratchblocks. Sorry that the emojis messed up script.
- MapleSyrup911
-
83 posts
split blocks
I think something like this would be easier to understand for new scratchers
(split (3) characters [left v] of [Hello this is some text]::operators)//Reports "Hel"
(split (3) characters [right v] of [Hello this is some text]::operators)//Reports "ext"
- mitdk
-
1000+ posts
split blocks
Yes, it would, but it does not solve the main problem. The block i am suggesting splits on a chosen character, not on a character #. I think something like this would be easier to understand for new scratchers(split (3) characters [left v] of [Hello this is some text]::operators)//Reports "Hel"
(split (3) characters [right v] of [Hello this is some text]::operators)//Reports "ext"
- PkmnQ
-
1000+ posts
split blocks
There seems to be a lot of confusion over what this does, so I've made a post that can be referred to.
(section (1) of split [a.b.c] on character [.] :: operators)This simply reports “a”. Think of it as a list, with “.” as a separator.
(section (1) of split [a..b] on character [..] :: operators)This simply reports “a”. The word “character” is misleading.
(section (1) of split [a,b] on character [.] :: operators)This simply reports “a,b”. It's sort of like a 1-item list.
(section (3) of split [a.b] on character [.] :: operators)This simply reports an empty string. It acts similarly to this block:
(item ( v) of [list v] :: list)
Last edited by PkmnQ (Oct. 23, 2020 04:17:15)
- awesome_guy6856
-
100+ posts
split blocks
workaround involves like 50 billion blocks and it's super complex and I hate it, so I support. However, I think the block you suggest is a little… not good. I think it would work better if it returned a list, and you could use list blocks on it. (Basically how .split() works in python)
Last edited by awesome_guy6856 (Oct. 23, 2020 18:16:15)
- Greg8128
-
500+ posts
split blocks
Due to the way Scratch works, you would only be able to select a list to add to, which isn't quite the same as returning a new list. But I agree workaround involves like 50 billion blocks and it's super complex and I hate it, so I support. However, I think the block you suggest is a little… not good. I think it would work better if it returned a list, and you could use list blocks on it. (Basically how .split() works in python)
- mitdk
-
1000+ posts
split blocks
Yes, I'll think of a ways to simplify.Due to the way Scratch works, you would only be able to select a list to add to, which isn't quite the same as returning a new list. But I agree workaround involves like 50 billion blocks and it's super complex and I hate it, so I support. However, I think the block you suggest is a little… not good. I think it would work better if it returned a list, and you could use list blocks on it. (Basically how .split() works in python)
- mitdk
-
1000+ posts
split blocks
Thanks! do you think that this would work better for the block? There seems to be a lot of confusion over what this does, so I've made a post that can be referred to.(section (1) of split [a.b.c] on character [.] :: operators)This simply reports “a”. Think of it as a list, with “.” as a separator.(section (1) of split [a..b] on character [..] :: operators)This simply reports “a”. The word “character” is misleading.(section (1) of split [a,b] on character [.] :: operators)This simply reports “a,b”. It's sort of like a 1-item list.(section (3) of split [a.b] on character [.] :: operators)This simply reports an empty string. It acts similarly to this block:(item ( v) of [list v] :: list)
(section (1) of split [a..b] on string [..] :: operators)
Last edited by mitdk (Oct. 25, 2020 21:17:48)
- rontinn
-
85 posts
split blocks
what if something has an odd number of characters and is split into two sections?
- mitdk
-
1000+ posts
split blocks
This block splits on a character, not evenly. for more explanations/examples, look at this: what if something has an odd number of characters and is split into two sections?
There seems to be a lot of confusion over what this does, so I've made a post that can be referred to.(section (1) of split [a.b.c] on character [.] :: operators)This simply reports “a”. Think of it as a list, with “.” as a separator.(section (1) of split [a..b] on character [..] :: operators)This simply reports “a”. The word “character” is misleading.(section (1) of split [a,b] on character [.] :: operators)This simply reports “a,b”. It's sort of like a 1-item list.(section (3) of split [a.b] on character [.] :: operators)This simply reports an empty string. It acts similarly to this block:(item ( v) of [list v] :: list)
Last edited by mitdk (Nov. 14, 2020 03:52:47)