Discuss Scratch
- Discussion Forums
- » Developing Scratch Extensions
- » Creating extensions for Scratch 3.0
- JimmiesAndTheMakers
-
18 posts
Creating extensions for Scratch 3.0
Save this code to your computer as a js file, in my case it is NitroBlock_3.js
Congratz, you now have your extension code created!!
You can use this tutorial to add it your own personal copy of scratch
Or, you can host the extension with gh-pages, and go here to test it (provide your own url, don't use mine)
Oh you're right
- supercatmaker2
-
41 posts
Creating extensions for Scratch 3.0
<cscratchblocks> {
getInfo() {
return {
“id”: “NitroBlock”,
“name”: “NitroBlock”,
“blocks”: [{
“opcode”: “substringy”,
“blockType”: “reporter”,
“text”: "letters through of “,
”arguments“: {
”num1“: {
”type“: ”number“,
”defaultValue“: ”2“
},
”num2“: {
”type“: ”number“,
”defaultValue“: ”5“
},
”string“: {
”type“: ”string“,
”defaultValue“: ”hello world“
}
}
},
}],
”menus": { //we will get back to this in a later tutorial
}
};
}
Scratch.extensions.register(new NitroBlock()); </scratchblocks>
getInfo() {
return {
“id”: “NitroBlock”,
“name”: “NitroBlock”,
“blocks”: [{
“opcode”: “substringy”,
“blockType”: “reporter”,
“text”: "letters through of “,
”arguments“: {
”num1“: {
”type“: ”number“,
”defaultValue“: ”2“
},
”num2“: {
”type“: ”number“,
”defaultValue“: ”5“
},
”string“: {
”type“: ”string“,
”defaultValue“: ”hello world“
}
}
},
}],
”menus": { //we will get back to this in a later tutorial
}
};
}
Scratch.extensions.register(new NitroBlock()); </scratchblocks>
- supercatmaker2
-
41 posts
Creating extensions for Scratch 3.0
class NitroBlock {
getInfo() {
return {
"id": "NitroBlock",
"name": "NitroBlock",
"blocks": [{
"opcode": "substringy",
"blockType": "reporter",
"text": "letters [num1] through [num2] of [string]",
"arguments": {
"num1": {
"type": "number",
"defaultValue": "2"
},
"num2": {
"type": "number",
"defaultValue": "5"
},
"string": {
"type": "string",
"defaultValue": "hello world"
}
}
},
}],
"menus": { //we will get back to this in a later tutorial
}
};
}
Scratch.extensions.register(new NitroBlock());
- supercatmaker2
-
41 posts
Creating extensions for Scratch 3.0
fgfgsaqsdfghjkuytr4ewsdcfgvhjuytredfghjhytrewedfghju7y453e2r345u6786u5t4r[quote]poooop:lol:[/quote]
- OhmanMasa23
-
1 post
Creating extensions for Scratch 3.0
But how do i make a block that shows an alert box?
- Elliot3-0
-
100+ posts
Creating extensions for Scratch 3.0
when green flag clicked
ask [Insert any code and I will translate] and wait
Translate code input-ed
- apple-kat
-
49 posts
Creating extensions for Scratch 3.0
Yooo Thanks! You helped me sooo much!In the developer console in Firefox you'll see: Hello! I have made a extension, and it's in a valid format! Only problem is that the extension won't load! On sheeptester, it just fails without warning. On turbowarp and adacraft, they say “can not load this extension”. How do I fix this error?
URL: https://raw.githubusercontent.com/TheChaosCommunity/TheChaosCommunity.github.io/main/se/MyScratchExtensions-main/WeirdBlocks/weirdblocks.jsThe resource from “https://raw.githubusercontent.com/TheChaosCommunity/TheChaosCommunity.github.io/main/se/MyScratchExtensions-main/WeirdBlocks/weirdblocks.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).For security reasons your browser will only give us a generic “could not load script” error instead of the real error. The real error will always be in the console, though.
The solution is to use GitHub Pages instead of raw.githubusercontent.com: https://thechaoscommunity.github.io/se/MyScratchExtensions-main/WeirdBlocks/weirdblocks.js
This still won't work because your syntax in getInfo is broken, but it gets you closer.
- apple-kat
-
49 posts
Creating extensions for Scratch 3.0
Oh no… I have another Problem:
Uncaught (in promise) TypeError: t is undefined
registerExtensionService extension-manager.js:307
Edit: Thats my Code: https://aha-ha.github.io/ScratchCam/1.1/extension.js
Uncaught (in promise) TypeError: t is undefined
registerExtensionService extension-manager.js:307
Edit: Thats my Code: https://aha-ha.github.io/ScratchCam/1.1/extension.js
Last edited by apple-kat (Dec. 25, 2022 14:33:36)
- GeckoTwin11
-
34 posts
Creating extensions for Scratch 3.0
YES WE DO!!! WE NEED SPEECH TO TEXT!
- Elliot3-0
-
100+ posts
Creating extensions for Scratch 3.0
okYES WE DO!!! WE NEED SPEECH TO TEXT!
- shinykrystal
-
49 posts
Creating extensions for Scratch 3.0
This can make it easier using the “Jila” coding language
By the way just ask for more code
SER(EXT-D0W)I’ll have more code here https://scratch.mit.edu/discuss/topic/655181/
/#:^Loads the extension in
By the way just ask for more code
- Gamerpro3000_2
-
56 posts
Creating extensions for Scratch 3.0
(#1)HOLY GOSH, thats a lot! i am likeCreating extensions for Scratch 3.0There is now official documentation regarding extensions!, but feel free to use this post to get you started
You'll want to start off by creating your extension's class, and register the extension - In my case, this would be ‘NitroBlock’class NitroBlock { //In both instances, NitroBlock will be the name in both instances } Scratch.extensions.register(new NitroBlock());
Next, we will be constructing block and menu definitions - We will continue to use ‘NitroBlock’ through this tutorialgetInfo() { return { "id": "NitroBlock", "name": "NitroBlock", "blocks": [ ], "menus": { //we will get back to this in a later tutorial } }; }
We are going to take a look at how blocks are constructed
For those of you that are familiar with extensions for Scratch 2.0, we will start off with this: - If not, you can ignore this['r', 'letters %n through %n of %s', 'substringy', '2', '5', 'hello world'] //breakdown below: ['r' = block type, 'letters %n through %n of %s' = block text, 'substringy' = block ID/opcode]{ "opcode": "substringy", //This will be the ID code for the block "blockType": "reporter", //This can either be Boolean, reporter, command, or hat "text": "letters [num1] through [num2] of [string]", //This is the block text, and how it will display in the Scratch interface "arguments": { //Arguments are the input fields in the block. In the block text, place arguments in square brackets with the corresponding ID "num1": { //This is the ID for your argument "type": "number", //This can be either Boolean, number, or string "defaultValue": "2" //This is the default text that will appear in the input field, you can leave this blank if you wish }, "num2": { "type": "number", "defaultValue": "5" }, "string": { "type": "string", "defaultValue": "hello world" } } },
We will put this newly constructed code into the blocks object above - My code will now look like thisclass NitroBlock { getInfo() { return { "id": "NitroBlock", "name": "NitroBlock", "blocks": [{ "opcode": "substringy", "blockType": "reporter", "text": "letters [num1] through [num2] of [string]", "arguments": { "num1": { "type": "number", "defaultValue": "2" }, "num2": { "type": "number", "defaultValue": "5" }, "string": { "type": "string", "defaultValue": "hello world" } } }, }], "menus": { //we will get back to this in a later tutorial } }; } Scratch.extensions.register(new NitroBlock());
Next we come to the most important part, the code that actually runs the blocks! - I am keeping this short and simple for tutorial's sake.//Make sure you name this function with with the proper ID for the block you defined above substringy({num1, num2, string}) { //these names will match the argument names you used earlier, and will be used as the variables in your code //this code can be anything you want return string.substring(num1 - 1, num2); //for reporters and Boolean blocks the important thing is to use 'return' to get the value back into Scratch. }
Place this new code below your getInfo() functionclass NitroBlock { getInfo() { return { "id": "NitroBlock", "name": "NitroBlock", "blocks": [{ "opcode": "substringy", "blockType": "reporter", "text": "letters [num1] through [num2] of [string]", "arguments": { "num1": { "type": "number", "defaultValue": "2" }, "num2": { "type": "number", "defaultValue": "5" }, "string": { "type": "string", "defaultValue": "hello world" } } }, }], "menus": { //we will get back to this in a later tutorial } }; substringy({num1, num2, string}) { return string.substring(num1 - 1, num2); }; }
Save this code to your computer as a js file, in my case it is NitroBlock_3.js
Congratz, you now have your extension code created!!
You can use this tutorial to add it your own personal copy of scratch
Or, you can host the extension with gh-pages, and go here to test it (provide your own url, don't use mine)
Here is the archived copy of my original post
when green flag clicked
brodcast (die)
Stop [all]
- scratchf02
-
11 posts
Creating extensions for Scratch 3.0
when green flag clicked
move (10) steps
define (☁ score)
- scratchf02
-
11 posts
Creating extensions for Scratch 3.0
when green flag clicked
move (☁ score) steps
wait (10) secs
say [](mouse x) for (2) secs
say (☁ score) for (2) secs
say for (2) secs
stop [all v]