Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast sprite name to string before getSpriteTargetByName #2038

Merged
merged 1 commit into from
Mar 8, 2019
Merged
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
2 changes: 2 additions & 0 deletions src/blocks/scratch3_motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Scratch3MotionBlocks {
targetX = Math.round(stageWidth * (Math.random() - 0.5));
targetY = Math.round(stageHeight * (Math.random() - 0.5));
} else {
targetName = Cast.toString(targetName);
const goToTarget = this.runtime.getSpriteTargetByName(targetName);
if (!goToTarget) return;
targetX = goToTarget.x;
Expand Down Expand Up @@ -127,6 +128,7 @@ class Scratch3MotionBlocks {
util.target.setDirection(Math.round(Math.random() * 360) - 180);
return;
} else {
args.TOWARDS = Cast.toString(args.TOWARDS);
const pointTarget = this.runtime.getSpriteTargetByName(args.TOWARDS);
if (!pointTarget) return;
targetX = pointTarget.x;
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/scratch3_sensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class Scratch3SensingBlocks {
targetX = util.ioQuery('mouse', 'getScratchX');
targetY = util.ioQuery('mouse', 'getScratchY');
} else {
args.DISTANCETOMENU = Cast.toString(args.DISTANCETOMENU);
const distTarget = this.runtime.getSpriteTargetByName(
args.DISTANCETOMENU
);
Expand Down Expand Up @@ -282,6 +283,7 @@ class Scratch3SensingBlocks {
if (args.OBJECT === '_stage_') {
attrTarget = this.runtime.getTargetForStage();
} else {
args.OBJECT = Cast.toString(args.OBJECT);
attrTarget = this.runtime.getSpriteTargetByName(args.OBJECT);
}

Expand Down
2 changes: 2 additions & 0 deletions src/sprites/rendered-target.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const log = require('../util/log');
const MathUtil = require('../util/math-util');
const StringUtil = require('../util/string-util');
const Cast = require('../util/cast');
const Clone = require('../util/clone');
const Target = require('../engine/target');
const StageLayering = require('../engine/stage-layering');
Expand Down Expand Up @@ -840,6 +841,7 @@ class RenderedTarget extends Target {
* @return {boolean} True iff touching a clone of the sprite.
*/
isTouchingSprite (spriteName) {
spriteName = Cast.toString(spriteName);
const firstClone = this.runtime.getSpriteTargetByName(spriteName);
if (!firstClone || !this.renderer) {
return false;
Expand Down
Binary file added test/fixtures/execute/sprite-number-name.sb2
Binary file not shown.