Special Split Block

split block script pic.png
I am trying to make such a block that looks like the one above that would report


, ignoring the (color) because it is in between ( and ). everything I have tried has failed miserably, and at this point I’m doubting if it is possible to do in a well-optimized manner. Any help is appreciated.

Is this any better than what you’ve come up with?

I’m confused, what’s the need for the strange unicode?

The idea is that it wouldn’t be in the string to be splitted

Oh.
What I am trying to make the block do is ignore everything in parentheses when splitting, since I do not always know what will be in the parentheses.

Can you give an example of your real world data that you want to do this strange split on?

It’s a list separated by commas, but I don’t want it to separate anything in parentheses. This also goes for a few other functions part of the data that has parentheses in it.
null, new Color(255, 230, 0), 9, 100, "hello", "world", true
After I change the string into a list using this split, I am going to change each item from a json item form into snap data except for the functions like the new color one.

I think it unlikely that you’ll find a single procedure in anyone’s string library that does exactly what you want.

Indeed, if you want this to be a library-quality (user-proof) block, you first have to specify what should happen in the case of nested parentheses in the text. That is, what should happen if, after you see an open paren, you see another open paren before you see a close paren? To do the general purpose right thing, you have to keep track of the current depth in parentheses at a given point in the string. And you have to handle syntax errors: What if you reach the end of the string while still inside parentheses, and what if you reach a close paren when you’re not inside parentheses? What if you see a parenthesis inside quotation marks? I would suggest that efficiency is the last thing for you to worry about.

Here’s how I would start:

I’m sure there’s some beautiful elegant functional way to do this, but in situations such as this one I admit I just throw up my hands and do it iteratively.

But I already see a bug; wherever it adds TOKEN to RESULT it should instead say

untitled script pic

Doesn’t seem to work :confused:

Welcome back though! 4 years gone is a lot, were you surprised to see how much snap has changed?

you can try using Untitled script pic(10) as a base

Is this better?

try it again

What was the change? they look the same to me, except the second one works perfectly.
I did decide to combine your 2 blocks which I did just for simplicity, but it was basically all you. Thanks so much for this help, you just saved me MANY hours.

Technical difficulties

I didn’t save the block before I took the script pic so it saved the right picture but not the right code, this is what it saved before:

But, your welcome!

oh, well thanks anyway!