Discuss Scratch

Noroz
Scratcher
33 posts

How to hack your own magic custom blocks

How do you save it to a zip?
Tropic
Scratcher
1000+ posts

How to hack your own magic custom blocks

Noroz wrote:

How do you save it to a zip?
Rename it from projectnamehere.sb2 to projectnamehere.zip. If the extensions (.zip, .sb2, etc.) are hidden, check the control panel and try to change the folder settings
dracoma20361
Scratcher
1 post

How to hack your own magic custom blocks

,mnhbgfgyu789098uihjbv vgtyu67yuhjbn bnj
Tropic
Scratcher
1000+ posts

How to hack your own magic custom blocks

dracoma20361 wrote:

,mnhbgfgyu789098uihjbv vgtyu67yuhjbn bnj
?
awesomeness01
Scratcher
97 posts

How to hack your own magic custom blocks

kvackkvack wrote:

cwkgavin367 wrote:

kvackkvack wrote:

cwkgavin367 wrote:

look at this project for cool scripts http://scratch.mit.edu/projects/33732648/#editor/
The project's not shared.
now it is
Cool, but it does not appear to be working
Working, but the block is a boolean when it should be a reporter.
awesomeness01
Scratcher
97 posts

How to hack your own magic custom blocks

Tropic wrote:

Noroz wrote:

How do you save it to a zip?
Rename it from projectnamehere.sb2 to projectnamehere.zip. If the extensions (.zip, .sb2, etc.) are hidden, check the control panel and try to change the folder settings
Or when it asks you to input the download name as you are saving it, type in your_project_name_here.zip .
awesomeness01
Scratcher
97 posts

How to hack your own magic custom blocks

Tropic wrote:

Feathercrown wrote:

Magnie wrote:

learnegy wrote:

Lightnin wrote:

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?
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.
A brilliant idea to finding the highest priority features and blocks. I support this.
I agree. Also, could you make a “open url” block? I bet you could, which would be really cool.
I agree with @learnegy
But I don't think a “open url” block would be that good since it may link to inappropriate websites. But maybe you can use the list of websites in the forums and make it only possible to link to websites that has been checked that they're secure?
Just make an experimental extension. I once made one that did exactly that, but since it contains an experimental extension, it can't be shared.
dhdguysg
Scratcher
100+ posts

How to hack your own magic custom blocks

Lel
when green flag clicked
Add [Lel] to [List 1 v] :: custom
// List 1 v is actully (ListChosen)
define Add (s :: custom-arg) to (ThisList :: custom-arg)
Add (s :: custom-arg) to (listChosen :: list)
LilAdamBrooks
Scratcher
99 posts

How to hack your own magic custom blocks

I really want to tell you something. It does not work.
Ziyad29
Scratcher
64 posts

How to hack your own magic custom blocks

Hardmath123 wrote:

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:
define [Fill [list] with [a],(n) times]
repeat (n)
|add [a] to [list v]
Pretty straightforward. Remember to make a list to get the list blocks!

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.
$ cd ~/path/to/zip's/folder
$ unzip Hack.zip
You should get a whole bunch of goodies:
  • project.json!
  • 0.png: this is the image which contains pen trails/stamps
  • 1,2,3.svg: costumes and backgrounds
  • 0.wav: sounds
The second two items are the defaults loaded into a project.
(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!
I'm sorry, but I do not get step #1. Can anyone help me please???!!! Thanks
powercon5
Scratcher
1000+ posts

How to hack your own magic custom blocks

cool
Tropic
Scratcher
1000+ posts

How to hack your own magic custom blocks

Ziyad29 wrote:

Hardmath123 wrote:

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:
define Fill [list] with [a],(n) times
repeat (n)
add [a] to [list v]
Pretty straightforward. Remember to make a list to get the list blocks!

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.
$ cd ~/path/to/zip's/folder
$ unzip Hack.zip
You should get a whole bunch of goodies:
  • project.json!
  • 0.png: this is the image which contains pen trails/stamps
  • 1,2,3.svg: costumes and backgrounds
  • 0.wav: sounds
The second two items are the defaults loaded into a project.
(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, right-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!
I'm sorry, but I do not get step #1. Can anyone help me please???!!! Thanks
I changed the quote a little. Maybe that will help?

Last edited by Tropic (Nov. 22, 2014 19:46:31)

yugi1024
Scratcher
30 posts

How to hack your own magic custom blocks

Hardmath123 wrote:

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:
define [Fill [list] with [a],(n) times]
repeat (n)
|add [a] to [list v]
Pretty straightforward. Remember to make a list to get the list blocks!

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.
$ cd ~/path/to/zip's/folder
$ unzip Hack.zip
You should get a whole bunch of goodies:
  • project.json!
  • 0.png: this is the image which contains pen trails/stamps
  • 1,2,3.svg: costumes and backgrounds
  • 0.wav: sounds
The second two items are the defaults loaded into a project.
(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!
I'm blank
yugi1024
Scratcher
30 posts

How to hack your own magic custom blocks

Tropic wrote:

Ziyad29 wrote:

Hardmath123 wrote:

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:
define Fill [list] with [a],(n) times
repeat (n)
add [a] to [list v]
Pretty straightforward. Remember to make a list to get the list blocks!

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.
$ cd ~/path/to/zip's/folder
$ unzip Hack.zip
You should get a whole bunch of goodies:
  • project.json!
  • 0.png: this is the image which contains pen trails/stamps
  • 1,2,3.svg: costumes and backgrounds
  • 0.wav: sounds
The second two items are the defaults loaded into a project.
(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, right-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!
I'm sorry, but I do not get step #1. Can anyone help me please???!!! Thanks
I changed the quote a little. Maybe that will help?
No offense, but it doesn't help at all.
Tropic
Scratcher
1000+ posts

How to hack your own magic custom blocks

yugi1024 wrote:

Hardmath123 wrote:

Hacking your own custom blocks
A tutorial

Basically, in this tutorial I'm going to demonstrate how to mess with blocks offline…

…Open up the Scratch project and select File>>Import from local drive. If it gives you any warnings, select “Ok”. Enjoy!
I'm blank
Don't you know what to do? I made it in colour here:

Hardmath123 wrote:

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:
define Fill [list] with [a],(n) times
repeat (n)
add [a] to [list v]
Pretty straightforward. Remember to make a list to get the list blocks!

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.
$ cd ~/path/to/zip's/folder
$ unzip Hack.zip
You should get a whole bunch of goodies:
  • project.json!
  • 0.png: this is the image which contains pen trails/stamps
  • 1,2,3.svg: costumes and backgrounds
  • 0.wav: sounds
The second two items are the defaults loaded into a project.
(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, right-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!
yugi1024
Scratcher
30 posts

How to hack your own magic custom blocks

Tropic wrote:

yugi1024 wrote:

I'm blank
Don't you know what to do? I made it in colour here:
I mean I didn't get the right JSON

Last edited by yugi1024 (Nov. 28, 2014 20:22:28)

Tropic
Scratcher
1000+ posts

How to hack your own magic custom blocks

yugi1024 wrote:

Tropic wrote:

yugi1024 wrote:

I'm blank
Don't you know what to do? I made it in colour here:
I mean I didn't get the right JSON
Didn't you understand the code in the JSON file? Or didn't you find it?
awesomeness01
Scratcher
97 posts

How to hack your own magic custom blocks

Can you put a reporter in the place of a block such as
move () steps
so you can essentially run the content of the variable as a regular block?
when green flag clicked
()
awesomeness01
Scratcher
97 posts

How to hack your own magic custom blocks

LilAdamBrooks wrote:

I really want to tell you something. It does not work.
Wrong! I've done it countless times.
yugi1024
Scratcher
30 posts

How to hack your own magic custom blocks

Tropic wrote:

yugi1024 wrote:

Tropic wrote:

yugi1024 wrote:

I'm blank
Don't you know what to do? I made it in colour here:
I mean I didn't get the right JSON
Didn't you understand the code in the JSON file? Or didn't you find it?
I got the file, but it was a lot different from the example.

Powered by DjangoBB