Discuss Scratch
- Discussion Forums
- » Developing Scratch Extensions
- » My Second-Ever Scratch Extension!
- 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:
Finally, here's the code:
ask [What's your name?] :: reporter extensionIf 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.
alert [Hello world!] :: extension
confirm [] :: boolean extension
installed? :: boolean extension // always true
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)
- ninjagolloyd
- Scratcher
500+ posts
My Second-Ever Scratch Extension!
this is cool but i think you can replace the installed function with this 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 extensionIf 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.
alert [Hello world!] :: extension
confirm [] :: boolean extension
installed? :: boolean extension // always true
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); })({});
ext.installed = function() { return true; }
[code=javascript][/code]
Last edited by ninjagolloyd (Aug. 1, 2017 16:40:44)
bean
- JGames101
- Scratcher
100+ posts
My Second-Ever Scratch Extension!
https://scratch.mit.edu/discuss/48/ pleaseWoops, sorry!
- JGames101
- Scratcher
100+ posts
My Second-Ever Scratch Extension!
Sorry! I see it's fixed now, though. Wrong forum.
- JGames101
- Scratcher
100+ posts
My Second-Ever Scratch Extension!
Thanks! I'm very new to JavaScript, so I missed that.this is cool but i think you can replace the installed function with this 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 extensionIf 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.
alert [Hello world!] :: extension
confirm [] :: boolean extension
installed? :: boolean extension // always true
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); })({});btw: useext.installed = function() { return true; }[code=javascript][/code]
- Discussion Forums
- » Developing Scratch Extensions
- » My Second-Ever Scratch Extension!