From b6dbf1fad4c26f7761cc7cb67c6d282288bf3921 Mon Sep 17 00:00:00 2001 From: rosics-code Date: Thu, 16 Apr 2026 22:51:15 -0400 Subject: [PATCH] Implement number conversion in Scratch3OperatorsBlocks Add convert method to Scratch3OperatorsBlocks for number conversion. --- .../src/blocks/scratch3_operators.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/scratch-vm/src/blocks/scratch3_operators.js b/packages/scratch-vm/src/blocks/scratch3_operators.js index cb5d6ef84fd..1d371ed0825 100644 --- a/packages/scratch-vm/src/blocks/scratch3_operators.js +++ b/packages/scratch-vm/src/blocks/scratch3_operators.js @@ -33,7 +33,8 @@ class Scratch3OperatorsBlocks { operator_contains: this.contains, operator_mod: this.mod, operator_round: this.round, - operator_mathop: this.mathop + operator_mathop: this.mathop, + operator_convert: this.convert }; } @@ -151,4 +152,19 @@ class Scratch3OperatorsBlocks { } } +convert (args) { + const num = Cast.toNumber(args.NUM); + const type = Cast.toString(args.CONVERT_TYPE); + + if (type === 'PERCENT') { + return num * 100; + } + + if (type === 'DECIMAL') { + return num / 100; + } + + return num; + } + module.exports = Scratch3OperatorsBlocks;