Replies: 6 comments
-
I'm pretty sure this is already in the JSON extension. |
Beta Was this translation helpful? Give feedback.
This comment was marked as disruptive content.
This comment was marked as disruptive content.
-
Yeah I agree. You shouldn't submit something that is a literal downgrade from an already existing extension. If you really want to add your extension or something just create a new pull request with your extension in it with your own folder. EDIT: it gets reviewed so don't expect it to get added |
Beta Was this translation helpful? Give feedback.
-
to awnser the question, look at contributing.md then make a pull request. they have standernds though, and have a hundred other pull requests to look at, so make sure your extension is solid before you do that. your extension is very small. |
Beta Was this translation helpful? Give feedback.
-
for example, you need to cast and not throw errors |
Beta Was this translation helpful? Give feedback.
-
Thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I have programmed an extension to convert strings into JSON arrays, and I would like to add it, but I don't know how to do that. Can someone help me with this?
Source code:
class StrictEqualityExtension {
getInfo() {
return {
id: "stringtolist",
name: "String to List",
color1: "#ed5a11",
color2: "#ed5a11",
blocks: [
{
opcode: "split",
blockType: Scratch.BlockType.REPORTER,
text: "Split [STR] by [SEP] [MAX] times",
arguments: {
STR: {
type: Scratch.ArgumentType.STRING,
defaultValue: "ScratchxCat",
},
SEP: {
type: Scratch.ArgumentType.STRING,
defaultValue: "x",
},
MAX: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "2",
},
},
},
{
opcode: "GetElement",
blockType: Scratch.BlockType.REPORTER,
text: "Item [I] from the String List [STR] times",
arguments: {
I: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "1",
},
STR: {
type: Scratch.ArgumentType.STRING,
defaultValue: '["Scratch","Cat"]',
},
},
},
],
};
}
split(args) {
var sep = args.SEP;
var str = args.STR;
var max = args.MAX;
if (max <= 0) {
return JSON.stringify(String(str).split(sep));
}
return JSON.stringify(String(str).split(sep, max));
}
GetElement(args) {
var i = args.I;
var str = args.STR;
return JSON.parse(str)[i - 1];
}
}
Scratch.extensions.register(new StrictEqualityExtension());
Beta Was this translation helpful? Give feedback.
All reactions