Discuss Scratch

JGames101
Scratcher
100+ posts

My Second-Ever Scratch Extension!

I had made a VERY simple scratch extension a while ago (It had 2 blocks: true and false), but recently I have been learning JavaScript, so I made another extension. This one is still very simple, only containing the following:
ask [What's your name?] :: reporter extension
alert [Hello world!] :: extension
confirm [] :: boolean extension
installed? :: boolean extension // always true
If you know JavaScript (which I assume you do) you probably know what all of these do, so I'm not going to explain. I know it's really basic, but it's only my second extension, and I'm still not very experienced with JavaScript.
Finally, here's the code:
(function(ext) {
    // Cleanup function when the extension is unloaded
    ext._shutdown = function() {};
    // Status reporting code
    // Use this to report missing hardware, plugin or unsupported browser
    ext._getStatus = function() {
        return {status: 2, msg: 'Ready'};
    };
    ext.ask_block = function(string) {
        return prompt(string);
    };
	
    ext.alert_block = function(string) {
        alert(string);
    };
    ext.confirm_block = function(string) {
        return confirm(string);
    };
    ext.installed = function() {
        return true;
    };
    // Block and block menu descriptions
    var descriptor = {
        blocks: [
            // Block type, block name, function name, param1 default value, param2 default value
        	['r', 'ask %s', 'ask_block', "What's your name?"],
		[' ', 'alert %s', 'alert_block', "hello world!"],
		['b', 'confirm %s', 'confirm_block', ""],
		['b', 'installed?', 'installed', ""],
        ]
    };
    // Register the extension
    ScratchExtensions.register('JGames101 Extension Test 2', descriptor, ext);
})({});

Last edited by JGames101 (Aug. 1, 2017 21:09:57)

Blaze349
Scratcher
1000+ posts

My Second-Ever Scratch Extension!

Wrong forum.
ninjagolloyd
Scratcher
500+ posts

My Second-Ever Scratch Extension!

JGames101 wrote:

I had made a VERY simple scratch extension a while ago (It had 2 blocks: true and false), but recently I have been learning JavaScript, so I made another extension. This one is still very simple, only containing the following:
ask [What's your name?] :: reporter extension
alert [Hello world!] :: extension
confirm [] :: boolean extension
installed? :: boolean extension // always true
If you know JavaScript (which I assume you do) you probably know what all of these do, so I'm not going to explain. I know it's really basic, but it's only my second extension, and I'm still not very experienced with JavaScript.
Finally, here's the code:
(function(ext) {
    // Cleanup function when the extension is unloaded
    ext._shutdown = function() {};
    // Status reporting code
    // Use this to report missing hardware, plugin or unsupported browser
    ext._getStatus = function() {
        return {status: 2, msg: 'Ready'};
    };
    ext.ask_block = function(string) {
        return prompt(string);
    };
	
    ext.alert_block = function(string) {
        alert(string);
    };
    ext.confirm_block = function(string) {
        return confirm(string);
    };
    ext.installed = function(string) {
        return true;
    };
    // Block and block menu descriptions
    var descriptor = {
        blocks: [
            // Block type, block name, function name, param1 default value, param2 default value
        	['r', 'ask %s', 'ask_block', "What's your name?"],
		[' ', 'alert %s', 'alert_block', "hello world!"],
		['b', 'confirm %s', 'confirm_block', ""],
		['b', 'installed?', 'installed', ""],
        ]
    };
    // Register the extension
    ScratchExtensions.register('JGames101 Extension Test 2', descriptor, ext);
})({});
this is cool but i think you can replace the installed function with this
ext.installed = function() {
    return true;
}
btw: use
[code=javascript][/code]

Last edited by ninjagolloyd (Aug. 1, 2017 16:40:44)


bean
JGames101
Scratcher
100+ posts

My Second-Ever Scratch Extension!

herohamp wrote:

https://scratch.mit.edu/discuss/48/ please
Woops, sorry!
JGames101
Scratcher
100+ posts

My Second-Ever Scratch Extension!

Blaze349 wrote:

Wrong forum.
Sorry! I see it's fixed now, though.
JGames101
Scratcher
100+ posts

My Second-Ever Scratch Extension!

ninjagolloyd wrote:

JGames101 wrote:

I had made a VERY simple scratch extension a while ago (It had 2 blocks: true and false), but recently I have been learning JavaScript, so I made another extension. This one is still very simple, only containing the following:
ask [What's your name?] :: reporter extension
alert [Hello world!] :: extension
confirm [] :: boolean extension
installed? :: boolean extension // always true
If you know JavaScript (which I assume you do) you probably know what all of these do, so I'm not going to explain. I know it's really basic, but it's only my second extension, and I'm still not very experienced with JavaScript.
Finally, here's the code:
(function(ext) {
    // Cleanup function when the extension is unloaded
    ext._shutdown = function() {};
    // Status reporting code
    // Use this to report missing hardware, plugin or unsupported browser
    ext._getStatus = function() {
        return {status: 2, msg: 'Ready'};
    };
    ext.ask_block = function(string) {
        return prompt(string);
    };
	
    ext.alert_block = function(string) {
        alert(string);
    };
    ext.confirm_block = function(string) {
        return confirm(string);
    };
    ext.installed = function(string) {
        return true;
    };
    // Block and block menu descriptions
    var descriptor = {
        blocks: [
            // Block type, block name, function name, param1 default value, param2 default value
        	['r', 'ask %s', 'ask_block', "What's your name?"],
		[' ', 'alert %s', 'alert_block', "hello world!"],
		['b', 'confirm %s', 'confirm_block', ""],
		['b', 'installed?', 'installed', ""],
        ]
    };
    // Register the extension
    ScratchExtensions.register('JGames101 Extension Test 2', descriptor, ext);
})({});
this is cool but i think you can replace the installed function with this
ext.installed = function() {
    return true;
}
btw: use
[code=javascript][/code]
Thanks! I'm very new to JavaScript, so I missed that.

Powered by DjangoBB