Discuss Scratch

samq64
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

RedGuy7 wrote:

samq64 wrote:

Do you know how to stop the blocks in my extension from instantly executing?

here's the code:

-Snip-
it should run when the block is press, right?
but you want it to run a few secconds after the block is pressed? google setTimeout
No, I meant if you make a script with that block, the script will never make it past the block as though it were an empty forever loop.
https://sheeptester.github.io/scratch-gui/?extension=https%3A%2F%2Fsamq64.github.io%2FScratchExtensions%2FMouseCursor.js

Try building this script and you'll see what I mean:
whenclickedswitchcursortoautosayHello!

Last edited by samq64 (April 29, 2021 20:56:53)

RedGuy7
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

samq64 wrote:

RedGuy7 wrote:

samq64 wrote:

Do you know how to stop the blocks in my extension from instantly executing?

here's the code:

-Snip-
it should run when the block is press, right?
but you want it to run a few secconds after the block is pressed? google setTimeout
No, I meant if you make a script with that block, the script will never make it past the block as though it were an empty forever loop.
https://sheeptester.github.io/scratch-gui/?extension=https%3A%2F%2Fsamq64.github.io%2FScratchExtensions%2FMouseCursor.js

Try building this script and you'll see what I mean:
whenclickedswitchcursortoautosayHello!
There's an error in the console “lib.min.js:166 vm Primitive rejected promise: ReferenceError: document is not defined”
Marc92020
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

What do I use to make the code?
samq64
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

Marc92020 wrote:

What do I use to make the code?
Any text editor, really. You can use Notepad if you like.

Last edited by samq64 (April 29, 2021 22:17:14)

crabraveprogrammer
Scratcher
100+ posts

Creating extensions for Scratch 3.0

does it not work for local files???
Marc92020
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

samq64 wrote:

Marc92020 wrote:

What do I use to make the code?
Any text editor, really. You can use Notepad if you like.
OK.
Marc92020
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

How do I put the url into the gui

and how do I make the url
samq64
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

Marc92020 wrote:

How do I put the url into the gui

and how do I make the url
Use GitHub pages, or any other website hosting service.

Last edited by samq64 (April 30, 2021 11:20:51)

Marc92020
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

How do I put the file into that website?
samq64
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

Marc92020 wrote:

How do I put the file into that website?
https://scratch.mit.edu/discuss/topic/289594/

Last edited by samq64 (April 30, 2021 13:29:38)

Marc92020
Scratcher
1000+ posts

Creating extensions for Scratch 3.0

samq64 wrote:

Marc92020 wrote:

How do I put the file into that website?
https://scratch.mit.edu/discuss/topic/289594/
what I mean is

marc92020.github.io/xxxxxxxxxxx/xxxxxxxxxxx.js
shipping123
Scratcher
12 posts

Creating extensions for Scratch 3.0

edbotinschools wrote:

Hi.
I currently have an HTTP extension in Scratch 2. Any ideas how I can convert this to Scratch 3??
Thanks.
C
You could try saving it to your computer in 2.0 and loading into 3.0.
shipping123
Scratcher
12 posts

Creating extensions for Scratch 3.0

magmacontainsI want new scratch extensions?ifiwantnewscratchextensionsthensayMake new onesfor2secselsesayAwwwwwwwwwwwwwwwww...for2secs
Barthdry
Scratcher
500+ posts

Creating extensions for Scratch 3.0

Free Bump.
werfghjtre
Scratcher
3 posts

Creating extensions for Scratch 3.0

Is it possible to make a WiFi one where project connects to WiFi?
whenclickedifWiFiConnectionthenbroadcastconnectedelsebroadcasterror in connection
I know that it would increase the possibilities for someone to post inappropriate stuff. But is there some way the Scratch Team could do some scratch approved apps; because I and many others are working on an Operating System (OS). It would also be nice to do this:

AskGoogle ?AskBing ?AskDuckDuckGo ?AskYahoo ?

If there is anything you could do like this then please do!

Thanks ,WERFGHJTRE

Last edited by werfghjtre (May 17, 2021 22:21:19)

DaWeeWee3
Scratcher
57 posts

Creating extensions for Scratch 3.0

Go to turbowarp.org
for example:
setpencolorto
  1. go to turbowarp
  • see inside
  • go to extensions
  • click on “Make your own extensions”
  • paste/type the link where the extension came from

Last edited by DaWeeWee3 (May 20, 2021 19:39:25)

Scratch_game_team
Scratcher
27 posts

Creating extensions for Scratch 3.0

NitroCipher wrote:

Creating extensions for Scratch 3.0


There 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 tutorial
getInfo() {
    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 this
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());

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() function
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
        }
    };
    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
Scratch_game_team
Scratcher
27 posts

Creating extensions for Scratch 3.0

Scratch 0.2 github code on vistas studio code program on no code uploud say and code understen me ı know code ım html codemanter
Scratch_game_team
Scratcher
27 posts

Creating extensions for Scratch 3.0

turbowarp html code
const logger = require('./logger');
const environment = require('./environment');

const INTERVAL = 1000 * 60 * 60;

const createRequestData = () => ({
total: 0,
notFound: 0,
});

const createBrowserData = () => ({
chrome: 0,
firefox: 0,
safari: 0,
other: 0,
none: 0
});

const createOSData = () => ({
windows: 0,
macos: 0,
chromeos: 0,
linux: 0,
android: 0,
ios: 0,
other: 0,
none: 0
});

const createPathsData = () => new Map();

const createUniquesData = () => new Set();

let requests = createRequestData();
let browser = createBrowserData();
let os = createOSData();
let paths = createPathsData();
let uniques = createUniquesData();
const reset = () => {
requests = createRequestData();
browser = createBrowserData();
os = createOSData();
paths = createPathsData();
uniques = createUniquesData();
};

const getData = () => ({
requests,
browser,
os,
paths,
uniques
});

const print = () => {
logger.info(`*** ${new Date().toUTCString()} ***`);

logger.info(`Requests: ${requests.total}`);
logger.info(` 404: ${requests.notFound}`);
logger.info(` Uniques: ${uniques.size}`);

logger.info('— Paths —');
const entries = Array.from(paths.entries()).sort((a, b) => b - a);
for (const of entries) {
logger.info(`${path} - ${hits}`);
}

logger.info('— OS —');
logger.info(` Windows: ${os.windows}`);
logger.info(` macOS: ${os.macos}`);
logger.info(` Linux: ${os.linux}`);
logger.info(`ChromeOS: ${os.chromeos}`);
logger.info(` Android: ${os.android}`);
logger.info(` iOS: ${os.ios}`);
logger.info(` Other: ${os.other}`);
logger.info(` None: ${os.none}`);

logger.info('— Browsers —');
logger.info(` Chrome: ${browser.chrome}`);
logger.info(` Firefox: ${browser.firefox}`);
logger.info(` Safari: ${browser.safari}`);
logger.info(` Other: ${browser.other}`);
logger.info(` None: ${browser.none}`);

reset();
};

if (!environment.isTest) {
setInterval(print, INTERVAL);
}

const handleRequest = (req) => {
if (req.headers !== ‘1’) {
const ip = req.ip;
uniques.add(ip);
}

const userAgent = req.headers;
if (typeof userAgent === ‘string’) {
if (userAgent.indexOf('Chrome') !== -1) {
browser.chrome++;
} else if (userAgent.indexOf('Firefox') !== -1) {
browser.firefox++;
} else if (userAgent.indexOf('Safari') !== -1) {
browser.safari++;
} else {
browser.other++;
}

if (userAgent.indexOf('Windows') !== -1) {
os.windows++;
} else if (userAgent.indexOf('iPhone') !== -1 || userAgent.indexOf('iPod') !== -1 || userAgent.indexOf('iPad') !== -1) {
os.ios++;
} else if (userAgent.indexOf('Mac OS') !== -1) {
os.macos++;
} else if (userAgent.indexOf('CrOS') !== -1) {
os.chromeos++;
} else if (userAgent.indexOf('Android') !== -1) {
os.android++;
} else if (userAgent.indexOf('Linux') !== -1) {
os.linux++;
} else {
os.other++;
}
} else {
browser.none++;
os.none++;
}
};

const handleServedFile = (path) => {
requests.total++;

if (path.endsWith('.html')) {
if (paths.has(path)) {
paths.set(path, paths.get(path) + 1);
} else {
paths.set(path, 1);
}
}
};

const handleNotFound = (path) => {
requests.notFound++;
};

module.exports = {
handleRequest,
handleServedFile,
handleNotFound,
reset,
getData
};
Scratch_game_team
Scratcher
27 posts

Creating extensions for Scratch 3.0

turbowarp code
<code>
const logger = require('./logger');
const environment = require('./environment');

const INTERVAL = 1000 * 60 * 60;

const createRequestData = () => ({
total: 0,
notFound: 0,
});

const createBrowserData = () => ({
chrome: 0,
firefox: 0,
safari: 0,
other: 0,
none: 0
});

const createOSData = () => ({
windows: 0,
macos: 0,
chromeos: 0,
linux: 0,
android: 0,
ios: 0,
other: 0,
none: 0
});

const createPathsData = () => new Map();

const createUniquesData = () => new Set();

let requests = createRequestData();
let browser = createBrowserData();
let os = createOSData();
let paths = createPathsData();
let uniques = createUniquesData();
const reset = () => {
requests = createRequestData();
browser = createBrowserData();
os = createOSData();
paths = createPathsData();
uniques = createUniquesData();
};

const getData = () => ({
requests,
browser,
os,
paths,
uniques
});

const print = () => {
logger.info(`*** ${new Date().toUTCString()} ***`);

logger.info(`Requests: ${requests.total}`);
logger.info(` 404: ${requests.notFound}`);
logger.info(` Uniques: ${uniques.size}`);

logger.info('— Paths —');
const entries = Array.from(paths.entries()).sort((a, b) => b - a);
for (const of entries) {
logger.info(`${path} - ${hits}`);
}

logger.info('— OS —');
logger.info(` Windows: ${os.windows}`);
logger.info(` macOS: ${os.macos}`);
logger.info(` Linux: ${os.linux}`);
logger.info(`ChromeOS: ${os.chromeos}`);
logger.info(` Android: ${os.android}`);
logger.info(` iOS: ${os.ios}`);
logger.info(` Other: ${os.other}`);
logger.info(` None: ${os.none}`);

logger.info('— Browsers —');
logger.info(` Chrome: ${browser.chrome}`);
logger.info(` Firefox: ${browser.firefox}`);
logger.info(` Safari: ${browser.safari}`);
logger.info(` Other: ${browser.other}`);
logger.info(` None: ${browser.none}`);

reset();
};

if (!environment.isTest) {
setInterval(print, INTERVAL);
}

const handleRequest = (req) => {
if (req.headers !== ‘1’) {
const ip = req.ip;
uniques.add(ip);
}

const userAgent = req.headers;
if (typeof userAgent === ‘string’) {
if (userAgent.indexOf('Chrome') !== -1) {
browser.chrome++;
} else if (userAgent.indexOf('Firefox') !== -1) {
browser.firefox++;
} else if (userAgent.indexOf('Safari') !== -1) {
browser.safari++;
} else {
browser.other++;
}

if (userAgent.indexOf('Windows') !== -1) {
os.windows++;
} else if (userAgent.indexOf('iPhone') !== -1 || userAgent.indexOf('iPod') !== -1 || userAgent.indexOf('iPad') !== -1) {
os.ios++;
} else if (userAgent.indexOf('Mac OS') !== -1) {
os.macos++;
} else if (userAgent.indexOf('CrOS') !== -1) {
os.chromeos++;
} else if (userAgent.indexOf('Android') !== -1) {
os.android++;
} else if (userAgent.indexOf('Linux') !== -1) {
os.linux++;
} else {
os.other++;
}
} else {
browser.none++;
os.none++;
}
};

const handleServedFile = (path) => {
requests.total++;

if (path.endsWith('.html')) {
if (paths.has(path)) {
paths.set(path, paths.get(path) + 1);
} else {
paths.set(path, 1);
}
}
};

const handleNotFound = (path) => {
requests.notFound++;
};

module.exports = {
handleRequest,
handleServedFile,
handleNotFound,
reset,
getData
};
</code>

Powered by DjangoBB