Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to hack your own magic custom blocks
- Alexcamostyle
-
81 posts
How to hack your own magic custom blocks
Never mind, I figured them both out.
EDIT: I have one more question though. Can I make a custom block set itself to a variable? In my score engine I'm trying to make a "Create score at X: () Y: () With a size of: () Using the variable: (var drop down menu)
EDIT: I have one more question though. Can I make a custom block set itself to a variable? In my score engine I'm trying to make a "Create score at X: () Y: () With a size of: () Using the variable: (var drop down menu)
Last edited by Alexcamostyle (Jan. 28, 2015 17:54:22)
- awesomeness01
-
97 posts
How to hack your own magic custom blocks
Even better…drop down menusI fixed the colourspoint towards [nowhere v] :: motion
switch costume [to cunvuzed cat thats weird v] :: looks
- MrSherlockHolmes
-
500+ posts
How to hack your own magic custom blocks
Is it possible to make a custom reporter with ‘r’? 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?
- Alexcamostyle
-
81 posts
How to hack your own magic custom blocks
Is there any way to create your own drop down menus in a custom hacked block?
- thirdlion
-
20 posts
How to hack your own magic custom blocks
Hacking your own custom blocks
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!
the part when you look in the zip to get the goodies i can't open it can you help me? i have a mac.
you have to have a app that unzips the zip file if you don't then you can not open the zip file like it says in the instructions

- awesomeness01
-
97 posts
How to hack your own magic custom blocks
You mean Never mind, I figured them both out.
EDIT: I have one more question though. Can I make a custom block set itself to a variable? In my score engine I'm trying to make a "Create score at X: () Y: () With a size of: () Using the variable: (var drop down menu)
? If so, just do %m.var in the variable name. For a complete list of dropdown list values, go here.Create score at X: (x) Y: (y) With size of (size) With variable [variable v] :: custom
- Alexcamostyle
-
81 posts
How to hack your own magic custom blocks
You mean Never mind, I figured them both out.
EDIT: I have one more question though. Can I make a custom block set itself to a variable? In my score engine I'm trying to make a "Create score at X: () Y: () With a size of: () Using the variable: (var drop down menu)? If so, just do %m.var in the variable name. For a complete list of dropdown list values, go here.Create score at X: (x) Y: (y) With size of (size) With variable [variable v] :: custom
Thanks for helping, but that's not what I'm having a problem with. This is:
define Create score at X: (x) Y: (y) Using the variable: (drop down)
say (drop down)
The script, when run, would say whatever the variable's name is, and not it's value. That's what I'm having trouble with. Thanks for helping though.

- awesomeness01
-
97 posts
How to hack your own magic custom blocks
Easy! First make a project in scratch and make it beYou mean Never mind, I figured them both out.
EDIT: I have one more question though. Can I make a custom block set itself to a variable? In my score engine I'm trying to make a "Create score at X: () Y: () With a size of: () Using the variable: (var drop down menu)? If so, just do %m.var in the variable name. For a complete list of dropdown list values, go here.Create score at X: (x) Y: (y) With size of (size) With variable [variable v] :: custom
Thanks for helping, but that's not what I'm having a problem with. This is:define Create score at X: (x) Y: (y) Using the variable: (drop down)
say (drop down)
The script, when run, would say whatever the variable's name is, and not it's value. That's what I'm having trouble with. Thanks for helping though.
define Create Score at X: (x) Y: (y) Using the variable [variable]and change “… using variable %s …” to “… using variable %m.var …”. Your custom block now looks like this:
say (variable)
Create score at X: (x) Y: (y) with variable [variable v] :: custom
- Alexcamostyle
-
81 posts
How to hack your own magic custom blocks
-snip-
Sorry, I really didn't explain that welll. I already hacked the block and added the custom drop-down menu, but it's doing what I said above even when I set the menu to a variable. (Saying the name and not the value.)
- juliopjbn
-
2 posts
How to hack your own magic custom blocks
It worked! Shane Vereen Super Bowl Jersey
Last edited by juliopjbn (Feb. 2, 2015 08:09:18)
- maxuper03
-
48 posts
How to hack your own magic custom blocks
Hacking your own custom blocks
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!
Help me! Project file is empty (I opened in notepad)
Last edited by maxuper03 (Feb. 15, 2015 19:41:02)
- endermanjd
-
37 posts
How to hack your own magic custom blocks
Even better…drop down menusI fixed the colourspoint towards [nowhere v] :: motion
switch costume [to cunvuzed cat thats weird v] :: looks
PLEASE HELP MEEEEEE [pretty please] :: motion
wait until [answerGiven] :: control
say [YIP YIP HOOORAY] :: looks
- endermanjd
-
37 posts
How to hack your own magic custom blocks
when red flag clicked
forever
ask [please help me? can you explain it more clear to me] and wait
if <you say no to me> then
broadcast [I WILL SCREEM v]
end
end
when I receive [I WILL SCREEM v]
your REALLY MEAN <SCREEM> then
YELLLLLL SCREEM SCREECH!
[please?]
- Alexcamostyle
-
81 posts
How to hack your own magic custom blocks
amazing XD
Last edited by Alexcamostyle (Feb. 16, 2015 04:44:31)
- i-will-not-tell-you
-
100+ posts
How to hack your own magic custom blocks
I think you should make it in to a project,so I can fav it!(and also love!)

- ealgase
-
100+ posts
How to hack your own magic custom blocks
Yes, make a block with one input. It can be reporter, Boolean, or string, it doesn't matter. Is there any way to create your own drop down menus in a custom hacked block?
define hackinput (dropdown)Now, download the project to your computer:
hackinput ()

Find the sb2 file on your desktop:

Rename it hack.zip:

If it gives you a prompt, hit OK:

Right-click, and click extract all:

When it gives you the next screen, just click extract:

Open the folder you extracted the files to:

IMPORTANT: delete the compressed zipped folder now.
In the folder that the files were extracted to, find and open project.json:


Now, turn word-wrap on:

Do control-f, and search for “Sprite1”:

Hit enter once:

Now find and select where it says
[["procDef", hackinput %n", ["dropdown"], [1], false]]]],

Replace %n with %n.list. There are many different menus that you can choose from, but for now you can do list. It will now read:
[["procDef", hackinput %m.list", ["dropdown"], [1], false]]]],

Now, right-click on the folder, and hover over send to. When the menu appears, click Compressed Zipped folder:

Rename the folder hack.sb2:

When it prompts you, click Yes:

Now, go into the original project, and upload the modified project:

Make a new list:

Now, go to more blocks. You should see a block with a dropdown menu!

- Discussion Forums
- » Help with Scripts
-
» How to hack your own magic custom blocks