Skip to content

Commit

Permalink
NOname-awa/more-comparisons: fix a lot of bugs (#1345)
Browse files Browse the repository at this point in the history
Almost every block in this extension has subtle inconsistencies but we
can't fix a lot of them because that could break projects.

All of the less than / greater than / between blocks were broken when
the inputs were strings. This is a pretty clear bug so we can change it
without worrying about breaking things that weren't relying on
objectively broken behavior.

https://github.com/TurboWarp/extensions/assets/33787854/c4899bc4-f60e-4a88-800e-b633d070e24c
  • Loading branch information
GarboMuffin authored Mar 7, 2024
1 parent 813d438 commit 4671894
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions extensions/NOname-awa/more-comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{
opcode: "equal",
blockType: Scratch.BlockType.BOOLEAN,
text: "[a] [b]",
text: "[a] == [b]",
arguments: {
a: {
type: Scratch.ArgumentType.STRING,
Expand Down Expand Up @@ -105,11 +105,11 @@
arguments: {
a: {
type: Scratch.ArgumentType.STRING,
defaultValue: "\n",
defaultValue: "1",
},
b: {
type: Scratch.ArgumentType.STRING,
defaultValue: "\n",
defaultValue: "2",
},
},
},
Expand Down Expand Up @@ -168,7 +168,7 @@
arguments: {
a: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "",
},
b: {
type: Scratch.ArgumentType.NUMBER,
Expand All @@ -183,7 +183,7 @@
arguments: {
a: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "",
},
b: {
type: Scratch.ArgumentType.NUMBER,
Expand All @@ -198,15 +198,15 @@
arguments: {
a: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "1",
},
b: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "2",
},
c: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "3",
},
},
},
Expand All @@ -217,15 +217,15 @@
arguments: {
a: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "1",
},
b: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "2",
},
c: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "\n",
defaultValue: "3",
},
},
},
Expand Down Expand Up @@ -474,10 +474,16 @@
return Math.abs(args.a - args.b) <= args.c;
}
between(args) {
return args.a < args.b && args.b < args.c;
return (
Scratch.Cast.compare(args.a, args.b) < 0 &&
Scratch.Cast.compare(args.b, args.c) < 0
);
}
betweenEqual(args) {
return args.a <= args.b && args.b <= args.c;
return (
Scratch.Cast.compare(args.a, args.b) <= 0 &&
Scratch.Cast.compare(args.b, args.c) <= 0
);
}
notEqual(args) {
return args.a != args.b;
Expand All @@ -486,10 +492,10 @@
return Scratch.Cast.toBoolean(args.a) !== Scratch.Cast.toBoolean(args.b);
}
equalOrGreater(args) {
return args.a >= args.b;
return Scratch.Cast.compare(args.a, args.b) >= 0;
}
equalOrLess(args) {
return args.a <= args.b;
return Scratch.Cast.compare(args.a, args.b) <= 0;
}
vertical(args) {
if (isNaN(args.a) || isNaN(args.b)) {
Expand Down

0 comments on commit 4671894

Please sign in to comment.