Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to hack your own magic custom blocks
- Warioware64
-
63 posts
How to hack your own magic custom blocks
Not it does not work on scratch 1.4. With the trick, it worksmy 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
Is it worth pointing out that things like Hardmath's “Magic KEYPRESS block” were already possible in 1.4? example
- MMHMMH
-
100+ posts
How to hack your own magic custom blocks
When I tried uploading your code to my project, it said the project failed to load…Does anyone know where I can get a free text editor that supports the JSON text? My notepad can't read it XD
Here's one. It's Notepad++(Windows only)(look for it on google or something). It supports JSON, and many other stuff(e.g. HTML, Javascript, Java, YAML, TeX, VB, Lua, Shell, Plain Text, Assembly, C, C#, C++, Python, Properties file, MS INI file).
Mac users could use a program called TextWrangler - this is the program I code with. TextWrangler is free and supports dozens of different programming languages.
- The_Hammer
-
13 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!
Can you please make a youtube video on it? I've tried it but it doesn't work and maybe im doing something wrong.
- Macie1234
-
100+ posts
How to hack your own magic custom blocks
So do I!I really like that idea!Perhaps, Scratch could just detect and label projects that use non-standard blocks, inputs, etc. Over time, you could track the use of various hacks and use the data as input when considering new features to implement in future versions. 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?
- nerdcraft
-
54 posts
How to hack your own magic custom blocks
You are just editing a safe SCRATCH program that doesn't fit your wants. will this put a virus on my pc? i just want to ask before I do it.
In short:
No
- supermarioboss
-
39 posts
How to hack your own magic custom blocks
http://beta.scratch.mit.edu/projects/10089070/You can get a lot more cloud variables without changing the JSON (Jason) code. You need to click the create variable button how many cloud variables you want in a row. Then move the windows/boxes so that you can see all of them. Name all of the variables in the text boxes and check the cloud variable check box on all of them. Press the create variable buttons on all of them. And there are your cloud variables. Note: This does not work if you already have 10 or more cloud variables. If you do, delete them so you have 9 or less. Then do what is above 15 cloud variables:
- The_Hammer
-
13 posts
How to hack your own magic custom blocks
Okay, I've been trying to get this to work for a few hours. I want to be able to check if<key (var) pressed?>.
Everything I try gives me
“Error: Project did not load”
I get the feeling this is my fault, and a syntax error, and I've tried a bunch of different syntax and I've come to the conclusion that I'm an idiot who should learn JS syntax but is too lazy, can someone tell me the correct syntax so I can get on my merry way to playing around with this?
no I always get that too (or im an idiot too)
- The_Hammer
-
13 posts
How to hack your own magic custom blocks
No, not at all! It's perfectly safe—all you're doing is editing a file and uploading it.
It doesn't seem to work for me. Can you make a youtube video for it please?
- hexagon400
-
61 posts
How to hack your own magic custom blocks
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?
… just say you've hacked it
- NolanAwesome
-
500+ posts
How to hack your own magic custom blocks
The Scratch Team has been notified because it doesn't work.
- Aar3811
-
32 posts
How to hack your own magic custom blocks
You could use that so you could put a Hacked/Modified tag by the blockPerhaps, Scratch could just detect and label projects that use non-standard blocks, inputs, etc. Over time, you could track the use of various hacks and use the data as input when considering new features to implement in future versions. 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?
Last edited by Aar3811 (June 17, 2014 14:25:32)
- chabad360
-
20 posts
How to hack your own magic custom blocks
wow this is genius now we really can do our own thing.
- chabad360
-
20 posts
How to hack your own magic custom blocks
does this work with color yes it does
Last edited by chabad360 (June 27, 2014 19:17:34)
- chabad360
-
20 posts
How to hack your own magic custom blocks
or we could just implement these in to the editor so this way we have a more wide range of things we can do.Bump. Lightnin? Can you please read this?Hmm. It's definitely a problem. I personally see doing this JSON-hacking a lot in the future, and not just for nefarious purposes—putting together an abnormally large script is much easier with a simply Python program. Also, being able to do this allows us to read Scratch projects, too, so I can imagine being able to implement a nice Scratch 2.0 to Snap! converter for Jens and Brian, or do a similar fun project. 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?
That said, it would definitely be confusing and intimidating to a new user; when I saw nXIII's highscore project I was totally lost (ok, intrigued, impressed and curious, but still admittedly lost).
One possible solution may be to change the way block definitions are stored, so that you can't hack in special inputs. You should only be able to have string and number and boolean inputs, the rest can gracefully become string inputs. That lets us continue messing with blocks in the JSON, but prevents odd-looking blocks. One issue with that is being able to stuff blocks into others offline—it can be awkward to explain how I fit a reporter into a dropdown to every new Scratcher who asks. Yet having, for example, a variable in the <key {} pressed?> block, is extremely useful.
I suppose the truth is that you can't completely disallow hacks just like you can't completely disallow chat rooms—there will always be the ingenuous, enterprising people who get around any walls you put up. But making the source completely closed and not letting anyone explore is pretty unfair, too. So I think the best ways is to actively discourage making scary-looking hacked blocks, but allow smaller things like stuffing reporters into dropdowns or making really long scripts with external programs.
Sorry, I did - just didn't get to respond to it. Thanks for pinging me about it with a comment to remind me.
A couple days ago we started a discussion on this by email, and John said:
“His suggestion would prevent making user-defined blocks with drop-down menu parameters via JSON. That's pretty easy and probably worth doing. It doesn't prevent all ”impossible to construct“ scripts but it would prevent user-defined blocks with input slots that can't be created via our block definition dialog.”
So it's likely on his list, with the 2000 other things.
The main concern I have about this technique is that if we have a ‘public code repository’ - which is one way of seeing the Scratch website - it's important that code is legible, makes sense, and corresponds accurately to what the project actually does. If hacking the JSON makes projects that don't behave how their scripts indicate they'd behave, or which can't be re-created with the normal editor, then I think it's potentially really confusing for anyone viewing the code. If some way of doing that becomes common, I'd recommend we think about validating uploads and rejecting hand JSON edits that can't be recreated in the editor. But if it's not much of an issue, we won't have to.
But as for making scripts by hacking the JSON that *can* be accurately represented / recreated in the editor - knock yourself out!
- 110Percent
-
100+ posts
How to hack your own magic custom blocks
What are the values for the different inputs instead of lists, such as variables, costumes, and Sprites? I know %m.list is for lists, what are the others?
- awesomeness01
-
97 posts
How to hack your own magic custom blocks
everything that I know: %s for string, %n for numerical value, %c for color, %d for dropdown, %b for boolean, and I thing that's it. Don't hold me to it, though. What are the values for the different inputs instead of lists, such as variables, costumes, and Sprites? I know %m.list is for lists, what are the others?
- CoolGuy3679
-
9 posts
How to hack your own magic custom blocks
I modified the code, sent it to a compressed zip folder, renamed it to a .sb2 file, but it didn't become a .sb2 file, it stayed as a .zip file! D: could you help me?
- MegaApuTurkUltra
-
1000+ posts
How to hack your own magic custom blocks
I just discovered a much easier way to hack custom blocks. It's easy, even newbs can do it. No downloading/JSON-editing required.
- Click “make a block”
- Type the %-thing directly into the name
- Enjoy your hacked block!
- wizzwizz4
-
92 posts
How to hack your own magic custom blocks
Yeah. If you've got a Windows 7, the steps are as follows: I modified the code, sent it to a compressed zip folder, renamed it to a .sb2 file, but it didn't become a .sb2 file, it stayed as a .zip file! D: could you help me?
- Go into Control Panel
- In the top right corner, search ‘Folder Options’
- Click on Folder Options, and then click on the ‘View’ tab.
- Below the ‘Hidden files and folders’ thing, there is a box labelled ‘Hide extensions for known file types’. Untick it. Press OK.
- In Windows Explorer, navigate to the annoying thing that won't become a Scratch Project. Remove the ‘.zip’ at the end.
If this doesn't work, or you have a different OS, please reply.