Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to hack your own magic custom blocks
- NASA-Space
-
100+ posts
How to hack your own magic custom blocks
My hacked block!
http://scratch.mit.edu/projects/16154456/#editor
How to make a Colour / Color block
1. Make a block
2. Write
3. Done
- ThePeanutMan98
-
3 posts
How to hack your own magic custom blocks
All you have to do is type whatever plain text you want in quotes. I can't seem to make the inputs go after specific words, so I'm pretty sure I can just change the format in the file, right?
- The_Duke
-
43 posts
How to hack your own magic custom blocks
oh wow this is wonderfully confusing XD can seem to get my head arround it
- ev3commander
-
500+ posts
How to hack your own magic custom blocks
Hacking your own custom blocksHey, what does the custom block look like?
A tutorial
Basically, in this tutorial I'm going to demonstrate how to mess with blocks offline so that you can manually insert reporters in forbidden spaces, and even create custom blocks.
Step 1: Setup
Open up a new Scratch 2.0 project and make a new custom block. For this tutorial, I'm going to make a block that automates a boring thing: adding a value many times to a list. You will be able to, with one block, add an arbitrary value to a list, an arbitrary number of times.
Make a new Scratch project, and add a new custom block:Pretty straightforward. Remember to make a list to get the list blocks!define [Fill [list] with [a],(n) times]
repeat (n)
|add [a] to [list v]
Step 2: Downloading a project
Now select File>>Export to local drive to save it to your local disk. In the popup, rename it to “Hack.zip”. Note the “.zip”, not “.sb2”. Pick any place to save it. Now, unarchive the zip.
On Mac or Windows, just double-click the zip file. On Mac and Linux, you can also use the “unzip” command-line utility.You should get a whole bunch of goodies:$ cd ~/path/to/zip's/folder $ unzip Hack.zipThe second two items are the defaults loaded into a project.
- project.json!
- 0.png: this is the image which contains pen trails/stamps
- 1,2,3.svg: costumes and backgrounds
- 0.wav: sounds
(At this point, you can safely delete the zip file.)
Step 3: Modifying the code!
Now, open up project.json in your favorite text editor/code editor. Here's what you should see:{ "objName": "Stage", "lists": [{ "listName": "dummy", "contents": [], "isPersistent": false, "target": "Stage", "x": 5, "y": 5, "width": 102, "height": 202, "visible": true }], "sounds": [{ "soundName": "pop", "soundID": 0, "md5": "83a9787d4cb6f3b7632b4ddfebf74367.wav", "sampleCount": 258, "rate": 11025, "format": "" }], "costumes": [{ "costumeName": "backdrop1", "baseLayerID": 3, "baseLayerMD5": "790f7842ea100f71b34e5b9a5bfbcaa1.svg", "rotationCenterX": 240, "rotationCenterY": 180 }], "currentCostumeIndex": 0, "penLayerMD5": "279467d0d49e152706ed66539b577c00.png", "tempoBPM": 60, "children": [{ "objName": "Scratch Cat", "scripts": [[53, 47.8, [["procDef", "Fill %s with %s , %n times", ["list", "a", "n"], ["", "", 1], true], ["doRepeat", ["getParam", "n"], [["append:toList:", ["getParam", "a"], "dummy"]]]]]], "sounds": [{ "soundName": "pop", "soundID": 0, "md5": "83a9787d4cb6f3b7632b4ddfebf74367.wav", "sampleCount": 258, "rate": 11025, "format": "" }], "costumes": [{ "costumeName": "costume1", "baseLayerID": 1, "baseLayerMD5": "f9a1c175dbe2e5dee472858dd30d16bb.svg", "rotationCenterX": 47, "rotationCenterY": 55 }, { "costumeName": "costume2", "baseLayerID": 2, "baseLayerMD5": "6e8bd9ae68fdb02b7e1e3df656a75635.svg", "rotationCenterX": 47, "rotationCenterY": 55 }], "currentCostumeIndex": 0, "scratchX": 0, "scratchY": 0, "scale": 1, "direction": 90, "rotationStyle": "normal", "isDraggable": false, "indexInLibrary": 1, "visible": true, "spriteInfo": { } }], "info": { "scriptCount": 1, "spriteCount": 1 } }
Don't panic! I'll walk you through it.
The format you see with all the colons and brackets is called JSON (JavaScript Object Notation). It's a simple notation to describe data structures. Read more here, but for now I'll explain the basics as we go.
If you have a search utility in your text editor (try ctrl-F), look for “Scratch Cat” (the name of the sprite in which we added the custom block).
These lines are what we will be messing with. “objName” means the sprite's name, and “scripts” is a list of scripts.
Replace that bit, up to but not including the line “sounds” with:"objName": "Scratch Cat", "scripts": [[28, 101.9, [["procDef", "Fill %m.list with %s , %n times", ["list", "a", "n"], ["", "something", 10], true], ["doRepeat", ["getParam", "n"], [["append:toList:", ["getParam", "a"], ["getParam", "list"]]] ]]]],
All I did was replace a text input with a list drop down. A complete list of %-things can be found here, courtesy nXIII. I also changed the input to the append function. Finally, I changed the default values in the first line for a professional look.
Step 4: Reuploading
Now save the json file and quit. You need to re-zip these files.
On Windows, right-click the folder in which you saved the original zip, and choose “Send to”>>“Compressed (Zipped) folder”. On Mac, rihgt-click the folder and select “Compress…”. On Mac and Linux you can also use the “zip” utility basically the same way we did above. Rename the new file to “Hack.sb2”.
Open up the Scratch project and select File>>Import from local drive. If it gives you any warnings, select “Ok”. Enjoy!
define Fill [list] with [a] (n) timesor…
define Fill list with [a] (n) times?
- lights0123
-
19 posts
How to hack your own magic custom blocks
Actually, you can do this is plain scratch: just name the custom block “%m.list” This is a cool hack, but my concern is that when anyone who doesn't know what you've done (or how you've done it) tries to view your project, they won't be able to understand your scripts - they won't even make sense.
I wouldn't mind at all if this was being done only with downloaded, local projects. But these are public, shared ones, that people are likely to “see inside”.
Any thoughts on the issue?
- rolledpie41
-
58 posts
How to hack your own magic custom blocks
Step 2: Downloading a project(for underlined) Can you show a screenshot?
Now select File>>Export to local drive to save it to your local disk. In the popup, rename it to “Hack.zip”. Note the “.zip”, not “.sb2”. Pick any place to save it. Now, unarchive the zip.
On Mac or Windows, just double-click the zip file. On Mac and Linux, you can also use the “unzip” command-line utility.
- goldfish678
-
1000+ posts
How to hack your own magic custom blocks
What do the red squares mean?
- Gichris04
-
31 posts
How to hack your own magic custom blocks
I don't have a text editor/code what is that?
- ariel2012
-
74 posts
How to hack your own magic custom blocks
Search notep
search notepad on your pc! I don't have a text editor/code what is that?
- GoldenDiamond
-
60 posts
How to hack your own magic custom blocks
sorry, does anyone have a project that has used that? I can't quite understand the meaning like how to do it… properly..
- GoldenDiamond
-
60 posts
How to hack your own magic custom blocks
sorry, does anyone have a project that has used that? I can't quite understand the meaning like how to do it… properly..
- dima365
-
36 posts
How to hack your own magic custom blocks
sorry, does anyone have a project that has used that? I can't quite understand the meaning like how to do it… properly..
I do
- meowmoo
-
500+ posts
How to hack your own magic custom blocks
do you download the custom block, program,or sprite?
- goldfish678
-
1000+ posts
How to hack your own magic custom blocks
The program. do you download the custom block, program,or sprite?
- meowmoo
-
500+ posts
How to hack your own magic custom blocks
@griffpatch 's ASCII key detector used hacked blocks… sorry, does anyone have a project that has used that? I can't quite understand the meaning like how to do it… properly..
<key [ (join [$] []) v] pressed?>
Last edited by meowmoo (April 12, 2014 12:22:25)
- GoldenDiamond
-
60 posts
How to hack your own magic custom blocks
sorry, does anyone have a project that has used that? I can't quite understand the meaning like how to do it… properly..
I do
…ok then thx, but can i have a link, coz you might have more than one project and most of them might mot use hacked blocks. and btw, i don't mean those ‘More Blocks’ I know that! am talking 'bout the hacked ones… how to do it …:\

- dima365
-
36 posts
How to hack your own magic custom blocks
sorry, does anyone have a project that has used that? I can't quite understand the meaning like how to do it… properly..
I do
…ok then thx, but can i have a link, coz you might have more than one project and most of them might mot use hacked blocks. and btw, i don't mean those ‘More Blocks’ I know that! am talking 'bout the hacked ones… how to do it …:\
It's right here.