Hide and Unhide a block of codes (Like folding feature in some editors)

As I start to build slightly longer blocks, even if I am using a large screen, I still find it not enough, therefore, I am asking whether it's possible, even through a hack, to be able to click a button to hide a block of codes, by logical structures, for example, that if...else block, or what's inside the chunky block we need to write inside the ring...

Another thing, I found sometimes it's difficult to position the drag and drop into the right empty spot, is there any best practices to make it easier?

After many tries, I started to get the hang of how to unringfy an input block in certain situation, you need to position your mouse to the exact oval edge... but what's the trick for people to use if they are not using mouse, rather keyboard? Any trick to achieve the same thing?

Finally, it sounds trivial, but I found the comments difficult to manage, if I move it ever so slightly, it will detach. I am asking whether anyone thought about create a comment block? - which is very easy to do, however, I would like this comment block also foldable, ie, with a click on the edge of the comment block, one can simply hide the majority of the comment lines, only leaves one line remain to be seen...

One more point after "Finally", :upside_down_face: Since I have imported many library functions and wrote quite a few of my own blocks, when I try to do a relabel (right click to bring up the option, then choose a different similar function), too many choices coming up, how could we narrow down the choices? Is there some best practices for this?

These are my wishful thinking...

Of course, I also welcome any tricks and/or workaround that you have found useful in your block building adventures...

Waiting for all of your comments and suggestions.

If you go into any category of type of block, at the bottom you will see "Make a block". If you click that, follow the directions, and drag your code into that block, then hit "Ok", your code will be however many lines in one block. If you need to copy, edit or check code from that set, you can right click and hit edit (at the bottom of the list when right clicked)

Make a block is not the same as variable btw, it just stores code.

I dont know about the comments, or anything else, but I hope this helps.

Thanks @inkybara for your response. Yes, I am using the "make a block" feature extensively - I guess that's what you are referring to. You are right, custom block is kind of hiding and unhiding by itself, but I am referring to the scenario that my custom block becomes big - especially if you are making a new class or obj, lots of code with if...statements for different methods and data, and chunky blocks inside the ring would make the block editor quite difficult to handle, that is my experience anyway.

When I get the chance, I will illustrate the comment block that I am talking about. I made quite a few, it's all trivial to make, with the exception that I want the text input to be able to accept multiline text field.

there are many situations where there's no way to divide up code in a way that makes sense entirely by itself, so it's not clear how a block could be named, and it becomes confusing to read.

custom block is kind of hiding and unhiding by itself, but I am referring to the scenario that my custom block becomes big

you can put custom blocks inside other custom blocks, and even inside itself

I want the text input to be able to accept multiline text field.

gear on the bottom right of the edit input dialog, you can create a multiline text input


Amazing, thanks @sarpnt , I never knew there is such an option. Really sweet. :upside_down_face:

Thanks to @sarpnt, now I made two comment blocks with multiline input capabilities.
comment block examples 2
The first one with a text-field where you can put comment, and c-block where you want your code commented out (no actions)
The second is another multiline comment block, with comments, and the code after runs
I also want another comment block, like the comment out block, but the C-block code should run, can I simply implement it with run block...? I haven't tested out yet, but thinking out loud....

Any comments and/or suggestions for these?

Yes, it works. I added a third type... the code will run, this could serve as the comment for the logical function of several blocks.

comment block examples 3

Anyway, I am just giving some ideas what I had in-mind, but I also would like the ability to hide/unhide those code at the click of the button, especially for the 1st or 3rd type of the comment blocks that I illustrated here.

just bear in mind that the comment blocks may slow down the code. When you're finished with your project, I suggest removing them, and adding snap comments in their place.

does it actually make a measurable difference? and on which ones?

Yes, this is definitely on our list of things to do When Things Slow Down™. We're thinking mainly about hiding everything under a hat block, so you can tell that the sprite responds to some condition but not know how until you expand that script. But hiding what's inside a C-slot is also part of the plan. No promises about when this will happen, though.

Yes, be sure to grab the block(s) you want to move by the top left corner. (I don't mean the exact corner pixel, just near the corner.) That helps a lot. Also sometimes it's best to fill empty slots from right to left; Snap! prefers to drop into an empty slot rather than push something out of a filled slot.

What, no, you shouldn't need to do that! Just right-click anywhere in the block body (i.e., not in an input slot).

Use the arrow keys to get the focus on the input slot containing the block or script you want to unringify. Then use the space key to open the context menu for that input slot, which should include ringify and unringify options. See page 131 of the manual.

Okay, this is one we haven't thought about! But yeah, when we do hiding we should include hiding of multiline inputs.

I just use
untitled script pic
for that.

If your program needs to run as fast as possible, then yeah, it does make a difference. If your script doesn't require as much speed as possible, then no, it shouldn't.

Thanks @ego-lay_atman-bay for your comments. Yes, if your project requires speedy execution, definitely a consideration.

However, a proper "supported" comment block(s) should be to optimize the same way, for example, for type 1 and type 2 comment blocks could be implemented similarly as "naked" blocks - just like Jens did for the turtle "costume" - I am one, but I am also not. So comment blocks implemented properly would be- I am a block, but I am also a non-block in a way... That way, the flow of the program would not be hindered, it's there to provide comments, right?

For type 3 comment block, it maybe a little trickier. Currently, I used the run c-block to make it... it will definitely have a performance hit, if used extensively. For those projects which don't have a critical time concern, current approach is fine. I have been using type 1 and type 2 for a while now, just modified the text field to accept multiline input, thanks to @sarpnt.

I do try to think of efficiency in my coding, but more from the algorithmic point of view, and early termination, that's why I like those library blocks such as find first item satisfy predicts in list/stream

Sometimes Warp may help and used as a simple solution, or choose run in Turbo mode. Just as an added question, is there any difference between warp and turbo mode under the hood?

Thanks @bh for your thoughtful comments.

I do realize you have a long to-do list, so I understand and appreciate the When Things Slow Down™ slogan... :slight_smile:

That's wonderful. If type 1 and type 3 comments blocks are implemented natively, we could fold the entire comments (hide/unhide) leaving only one line of the text field visible...

Thanks for this tip. I will try it out.

Yes, that's what I found out as well.

But that's not my experience at all, that's the reason. Take a look at the following example:

Unringify difficult

I cooked up the above example for illustration purposes. Now, obviously we need to unringify the predict slot of the keep items block for the comparison function (from item 1 of a list) which gets fed into the predict of the keep items from list block. Now, you try to unringify, you have to carefully move the mouse around to the edge of the inner-oval to almost the perfect spot before you could see the unringify choice. Am I doing something wrong? (never mind, finally I got it work, I was clicking on the outside grey part all these times, I have to click inside)

I could not get it to work.

Not just commented out, but with comments in the text field too...if you could take a read again, with type 1, I can write in comments why I commented this out... It's more like in c/c++, but in one
// I am going to comment the follow code blocks out
// these may not be efficient enough
// now I have a new algorithm to implement this...
code blocks...
Help this makes sense to you and thank you for engaging in this discussion.

By the way, for the first comment out block, if someone has the skill to make the border semi-transparent, that will remind me this code is commented out... just wishful thinking... I don't know how to change the color of these custom blocks, at least haven't learned how yet...
That will also differentiate between type 1 and 3 comments...

I don't know how to change the color of these custom blocks, at least haven't learned how yet...

you need to select a category when making the block (the make a block button appears in every block category in the palette too, and sets the default to that)

you can also go to file > new category and can select a custom color for it

Thanks @sarpnt for this. I knew there is a new category feature, but I never really used it, now I know you could customize colors too. So wonderful, I am getting lots of amazing tips from you.

Is there a way to change the category of the existing custom blocks? (just figured this one out, you can do from the block editor, just right click on the block title, and select edit) Or if there is a way also change the type say from command to reporter or to predicate? I read somewhere in the manual you could essentially change anything, some of them require some hacking, possibly. But I haven't looked into closely yet.

That is a bit more tricky. To do it, you need to remove every use of the block, then just right-click the block in the block editor, and select edit. There might be options to change the block type.

just hover and drag over text and press q to make a quote.

Thanks @ego-lay_atman-bay,

I think it's only possible before you hit the apply or okay button during the block creation process. But I will try later...

On a related note, how do I change the label of the custom block? Is label used when we are searching for the block (Control-F)?