Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/blocks/scratch3_looks.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ class Scratch3LooksBlocks {
}

think (args, util) {
this.runtime.emit(Scratch3LooksBlocks.SAY_OR_THINK, util.target, 'think', args.MESSAGE);
this._think(args.MESSAGE, util.target);
}
_think (message, target) { // used by compiler
this.runtime.emit(Scratch3LooksBlocks.SAY_OR_THINK, target, 'think', message);
}

thinkforsecs (args, util) {
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/compat-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
const stacked = [
'looks_changestretchby',
'looks_hideallsprites',
'looks_say',
'looks_sayforsecs',
'looks_setstretchto',
'looks_switchbackdroptoandwait',
'looks_think',
'looks_thinkforsecs',
'motion_align_scene',
'motion_glidesecstoxy',
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ const StackOpcode = {
LOOKS_BACKDROP_SET: 'looks.switchBackdrop',
LOOKS_COSTUME_NEXT: 'looks.nextCostume',
LOOKS_COSTUME_SET: 'looks.switchCostume',
LOOKS_SAY: 'looks.say',
LOOKS_THINK: 'looks.think',

MOTION_X_SET: 'motion.setX',
MOTION_X_CHANGE: 'motion.changeX',
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/irgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ class ScriptTreeGenerator {
return new IntermediateStackBlock(StackOpcode.LOOKS_BACKDROP_NEXT);
case 'looks_nextcostume':
return new IntermediateStackBlock(StackOpcode.LOOKS_COSTUME_NEXT);
case 'looks_say':
return new IntermediateStackBlock(StackOpcode.LOOKS_SAY, {
message: this.descendInputOfBlock(block, 'MESSAGE')
});
case 'looks_seteffectto':
return new IntermediateStackBlock(StackOpcode.LOOKS_EFFECT_SET, {
effect: block.fields.EFFECT.value.toLowerCase(),
Expand All @@ -825,6 +829,10 @@ class ScriptTreeGenerator {
return new IntermediateStackBlock(StackOpcode.LOOKS_COSTUME_SET, {
costume: this.descendInputOfBlock(block, 'COSTUME', true)
});
case 'looks_think':
return new IntermediateStackBlock(StackOpcode.LOOKS_THINK, {
message: this.descendInputOfBlock(block, 'MESSAGE')
});

case 'motion_changexby':
return new IntermediateStackBlock(StackOpcode.MOTION_X_CHANGE, {
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/jsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,12 @@ class JSGenerator {
case StackOpcode.LOOKS_COSTUME_SET:
this.source += `runtime.ext_scratch3_looks._setCostume(target, ${this.descendInput(node.costume)});\n`;
break;
case StackOpcode.LOOKS_SAY:
this.source += `runtime.ext_scratch3_looks._say(${this.descendInput(node.message)}, target);\n`;
break;
case StackOpcode.LOOKS_THINK:
this.source += `runtime.ext_scratch3_looks._think(${this.descendInput(node.message)}, target);\n`;
break;

case StackOpcode.MOTION_X_CHANGE:
this.source += `target.setXY(target.x + ${this.descendInput(node.dx)}, target.y);\n`;
Expand Down
23 changes: 10 additions & 13 deletions test/snapshot/__snapshots__/order-library-reverse.sb3.tw-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = stage.variables["p]KODv+)+:l=%NT~j3/d-order"];
const b1 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
const b2 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
b0.value = 0;
thread.timer = timer();
Expand All @@ -18,52 +17,50 @@ yield;
thread.timer = null;
b0.value = ((+b0.value || 0) + 1);
if ((b0.value === 1)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (1)",}, b2, false, false, "]4hbk*5ix]V00h|!x1oy", null);
runtime.ext_scratch3_looks._say("pass order is correct (1)", target);
} else {
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 1 != " + ("" + b0.value)),}, b2, false, false, "H=x@7SpNJeX|!}8x5y4,", null);
runtime.ext_scratch3_looks._say(("fail order is incorrect 1 != " + ("" + b0.value)), target);
}
retire(); return;
}; })

// Sprite3 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
const b1 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
const b0 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 2",}, b0, false, false, "1Ba%a0GIK#hwJ46y=WVt", null);
runtime.ext_scratch3_looks._say("plan 2", target);
thread.timer = timer();
var a0 = Math.max(0, 1000 * (+b1.value || 0));
var a0 = Math.max(0, 1000 * (+b0.value || 0));
runtime.requestRedraw();
yield;
while (thread.timer.timeElapsed() < a0) {
yield;
}
thread.timer = null;
thread.timer = timer();
var a1 = Math.max(0, 1000 * (+b1.value || 0));
var a1 = Math.max(0, 1000 * (+b0.value || 0));
runtime.requestRedraw();
yield;
while (thread.timer.timeElapsed() < a1) {
yield;
}
thread.timer = null;
thread.timer = timer();
var a2 = Math.max(0, 1000 * (+b1.value || 0));
var a2 = Math.max(0, 1000 * (+b0.value || 0));
runtime.requestRedraw();
yield;
while (thread.timer.timeElapsed() < a2) {
yield;
}
thread.timer = null;
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "}-I/zE+.RSi`:h[RxMvQ", null);
runtime.ext_scratch3_looks._say("end", target);
retire(); return;
}; })

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = stage.variables["p]KODv+)+:l=%NT~j3/d-order"];
const b1 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
const b2 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
b0.value = 0;
thread.timer = timer();
Expand All @@ -76,9 +73,9 @@ yield;
thread.timer = null;
b0.value = ((+b0.value || 0) + 1);
if ((b0.value === 2)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (2)",}, b2, false, false, "0i[-T:vYTt=bi47@byUE", null);
runtime.ext_scratch3_looks._say("pass order is correct (2)", target);
} else {
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 2 != " + ("" + b0.value)),}, b2, false, false, "Coc1aZ;L9M-RyEt`syps", null);
runtime.ext_scratch3_looks._say(("fail order is incorrect 2 != " + ("" + b0.value)), target);
}
retire(); return;
}; })
23 changes: 10 additions & 13 deletions test/snapshot/__snapshots__/order-library.sb3.tw-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,41 @@

// Sprite3 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
const b1 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
const b0 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 2",}, b0, false, false, "s+@:|^WPr8]N1Y9Hk2f5", null);
runtime.ext_scratch3_looks._say("plan 2", target);
thread.timer = timer();
var a0 = Math.max(0, 1000 * (+b1.value || 0));
var a0 = Math.max(0, 1000 * (+b0.value || 0));
runtime.requestRedraw();
yield;
while (thread.timer.timeElapsed() < a0) {
yield;
}
thread.timer = null;
thread.timer = timer();
var a1 = Math.max(0, 1000 * (+b1.value || 0));
var a1 = Math.max(0, 1000 * (+b0.value || 0));
runtime.requestRedraw();
yield;
while (thread.timer.timeElapsed() < a1) {
yield;
}
thread.timer = null;
thread.timer = timer();
var a2 = Math.max(0, 1000 * (+b1.value || 0));
var a2 = Math.max(0, 1000 * (+b0.value || 0));
runtime.requestRedraw();
yield;
while (thread.timer.timeElapsed() < a2) {
yield;
}
thread.timer = null;
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "7e7aA!PF-sxf1uka+sh2", null);
runtime.ext_scratch3_looks._say("end", target);
retire(); return;
}; })

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = stage.variables["):/PVGTvoVRvq(ikGwRE-order"];
const b1 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
const b2 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
b0.value = 0;
thread.timer = timer();
Expand All @@ -52,9 +50,9 @@ yield;
thread.timer = null;
b0.value = ((+b0.value || 0) + 1);
if ((b0.value === 1)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (1)",}, b2, false, false, "RSQ{nVCc)6E)(`KlnFCF", null);
runtime.ext_scratch3_looks._say("pass order is correct (1)", target);
} else {
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 1 != " + ("" + b0.value)),}, b2, false, false, "8k^j~`c^|YO@hkFd?~2d", null);
runtime.ext_scratch3_looks._say(("fail order is incorrect 1 != " + ("" + b0.value)), target);
}
retire(); return;
}; })
Expand All @@ -63,7 +61,6 @@ retire(); return;
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = stage.variables["):/PVGTvoVRvq(ikGwRE-order"];
const b1 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
const b2 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
b0.value = 0;
thread.timer = timer();
Expand All @@ -76,9 +73,9 @@ yield;
thread.timer = null;
b0.value = ((+b0.value || 0) + 1);
if ((b0.value === 2)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (2)",}, b2, false, false, "KP?op(=Vg2#;@]!,C#.~", null);
runtime.ext_scratch3_looks._say("pass order is correct (2)", target);
} else {
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 2 != " + ("" + b0.value)),}, b2, false, false, "=]|}L~4uQXTNtwJKw_;R", null);
runtime.ext_scratch3_looks._say(("fail order is incorrect 2 != " + ("" + b0.value)), target);
}
retire(); return;
}; })
47 changes: 23 additions & 24 deletions test/snapshot/__snapshots__/tw-NaN.sb3.tw-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,71 @@

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 21",}, b0, false, false, "B", null);
runtime.ext_scratch3_looks._say("plan 21", target);
if (!(("" + (0 / 0)).toLowerCase() === "0".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aA", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + (0 * Infinity)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "/", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if (((((0 * Infinity) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "?", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + ((Math.acos(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "=", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((((((Math.acos(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "]", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + ((Math.asin(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "_", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((((((Math.asin(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "{", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + (0 / 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "}", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if (((((0 / 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aa", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + Math.sqrt(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ac", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((((Math.sqrt(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ae", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + mod(0, 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ag", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((((mod(0, 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ai", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + Math.log(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ak", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((((Math.log(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "am", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((("" + (Math.log(-1) / Math.LN10)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ao", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if (((((Math.log(-1) / Math.LN10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aq", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if (((((Math.round(Math.sin((Math.PI * (1 / 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "as", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if (((((Math.round(Math.cos((Math.PI * (1 / 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "au", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((((tan((1 / 0)) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aw", null);
runtime.ext_scratch3_looks._say("pass", target);
}
if ((((runtime.ext_scratch3_operators._random((-1 / 0), (1 / 0)) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ax", null);
runtime.ext_scratch3_looks._say("pass", target);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, ":", null);
runtime.ext_scratch3_looks._say("end", target);
retire(); return;
}; })
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "6_?4sPB-|g:DtjdOm5Q-", null);
runtime.ext_scratch3_looks._say("plan 1", target);
if (!((Infinity + -Infinity) <= 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ")-u2YbbMb;gXMPOidjPj", null);
runtime.ext_scratch3_looks._say("pass", target);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "zqE}hdaes.b)@mO1{R;X", null);
runtime.ext_scratch3_looks._say("end", target);
retire(); return;
}; })
7 changes: 3 additions & 4 deletions test/snapshot/__snapshots__/tw-all-at-once.sb3.tw-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "1TRvh{mBarwY!BX8`o$R", null);
runtime.ext_scratch3_looks._say("plan 1", target);
if (true) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "K|r`QjC126S.93lMawiD", null);
runtime.ext_scratch3_looks._say("pass", target);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "QaZ%(g:;bB~D+24z:U?l", null);
runtime.ext_scratch3_looks._say("end", target);
retire(); return;
}; })
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
const b1 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"];
const b2 = stage.variables["FpLI$ida6)qR,q~y`1|*"];
const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"];
const b1 = stage.variables["FpLI$ida6)qR,q~y`1|*"];
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "j", null);
b1.value = (1 + 2);
runtime.ext_scratch3_looks._say("plan 1", target);
b0.value = (1 + 2);
yield* thread.procedures["Znon-warp recursion %s"](2);
if ((("" + listGet(b2.value, b1.value)).toLowerCase() === "the only thing".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "t", null);
if ((("" + listGet(b1.value, b0.value)).toLowerCase() === "the only thing".toLowerCase())) {
runtime.ext_scratch3_looks._say("pass", target);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "s", null);
runtime.ext_scratch3_looks._say("end", target);
retire(); return;
}; })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
const b1 = target.variables["null"];
const b0 = target.variables["null"];
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 0",}, b0, false, false, "a", null);
b1.value = 5;
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "d", null);
runtime.ext_scratch3_looks._say("plan 0", target);
b0.value = 5;
runtime.ext_scratch3_looks._say("end", target);
retire(); return;
}; })
Loading