-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
110 lines (110 loc) · 2.93 KB
/
code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
class varsnum {
getInfo() {
return {
id: 'varsnums', // change this if you make an actual extension!
name: 'Extra Stuff',
blocks: [
{
opcode: 'strictlyEquals',
blockType: Scratch.BlockType.BOOLEAN,
text: '[ONE]',
arguments: {
ONE: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'true'
}
}
},
{
opcode: 'runjs',
blockType: Scratch.BlockType.REPORTER,
text: 'Run Code:\n[ONE]',
arguments: {
ONE: {
type: Scratch.ArgumentType.STRING,
defaultValue: "return true"
}
}
},
{
opcode: 'stackfornothing',
blockType: Scratch.BlockType.COMMAND,
text: '[ONE]',
arguments: {
ONE: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Use this with Run Code: ()'
}
}
},
{
opcode: 'setoop',
blockType: Scratch.BlockType.REPORTER,
text: 'Make a object with contents [ONE]',
arguments: {
ONE: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'test: "Hello, world",test2: "hhfhgh"'
}
}
},
{
opcode: 'getoop',
blockType: Scratch.BlockType.REPORTER,
text: 'Get item [ONE] from [TWO]',
arguments: {
ONE: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'text'
},
TWO: {
type: Scratch.ArgumentType.STRING,
defaultValue: '{"text": 5}'
}
}
},
{
opcode: 'addoop',
blockType: Scratch.BlockType.REPORTER,
text: 'Set value [ONE] on item [TWO] on object [THREE]',
arguments: {
ONE: {
type: Scratch.ArgumentType.STRING,
defaultValue: '5'
},
TWO: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'test'
},
THREE: {
type: Scratch.ArgumentType.STRING,
defaultValue: '{}'
},
}
}
]
};
}
strictlyEquals(args) {
// Note strict equality: Inputs must match exactly: in type, case, etc.
return args.ONE;
}
runjs(args) {
return Function(args.ONE)()
}
stackfornothing(args) {
// Do nothing
}
setoop(args) {
return JSON.stringify(Function("return {"+args.ONE+"}")())
}
getoop(args) {
return JSON.parse(args.TWO)[args.ONE]
}
addoop(args) {
var i = JSON.parse(args.THREE)
i[args.TWO] = args.ONE
return JSON.stringify(i)
}
}
Scratch.extensions.register(new varsnum());