What are shadowed blocks?
Yesterday I introduced you to hacking Scratch. I asked what you'd like me to explain next, and I received two requests:
BusterBrown1218 asked:
Can you tell us how to put blocks inside of a define block?
Raihan142857 asked:
How do you hack a custom block to make it have dropdown inputs?
Funnily enough, these two are both related to a block's shadow property, and so that is what I will talk about today. Begin by thinking of a block with a round dropdown, such as the key pressed? block (it must have a round dropdown, not a square dropdown, like a set variable to block).
The Scratch editor counts this as a single block, but actually the dropdown is counted as its own block. If you download the project and open the project.json, as I showed you last time, you'll see two different blocks: one has the opcode sensing_keypressed, and the other, sensing_keyoptions. The last one is the dropdown where you can select what key to use. If you look at the properties of the first block, you'll see that its shadow property is false. The second one, however, has it set to true.
The dropdown is essentially a 'shadow': it's darker than the key pressed? block, and can't be moved independently. But what happens if you set its shadow property to false? In that case, you will see the block on the left:
Now, the dropdown is no longer a shadow. You can take it out of the key pressed? block, as shown on the right. Notice how the input is now just a hole, you can't type in it.
The block definition shown below is actually three blocks, with opcodes procedures_definiton, procedure_prototype and argument_reporter_string_number in order from left to right.
The second one is in fact a shadow block, and if you set its shadow to false, you will be able to move it, and put blocks under, answering BusterBrown1218's question. Play around with it: you'll find that you can put normal blocks under it, but not on top of it. Have a go!
Let's go back to Raihan's question. Here's a simple way to put any dropdown into any text input. First, drag the block you want to put the dropdown in, and the block that contains the dropdown you want. For example, if you want to put a costume dropdown into a custom block, drag out the custom block, and a switch to costume block:
Download the project, unzip it, and open the project.json file as I showed you. Locate the blocks you dragged out. In this case, they are procedure_call and looks_switchcostumeto. What we're going to do is swap the inputs around: the first block will have the dropdown, and the second will end up with a text input. Open the inputs property of each block, and open the input you're interested in: in this case there is only one input for each block. To swap the inputs around, select all the contents of the input with the box icon, and move it with the icon with 6 dots. Here's a video:
Now download the new JSON, zip the files and upload it to Scratch. The dropdown will now have moved!
A lot of what I know about hacking Scratch I discovered by experimenting, and I encourage you to do the same: try to find out what happens if you set make a regular shadowed. What happens if you make a block under another block shadowed? You'll also notice that the dropdown for messages is different to the rest. Anyway, thank you for reading! If you had any problems, please ask me, and give me suggestions for what to talk on next!
~ qucchia