Store references to target in say blocks

As part of reusing the block utility object, asynchronous say block
functions cannot use the utility in a promise or timeout asynchronous
handle. Store the needed target reference so utility is not needed
later.
This commit is contained in:
Michael "Z" Goddard committed 2017-11-07 10:21:52 -05:00
1 parent bbe7981703
commit e3dfe24d7f
1 file changed
+4 -2
+4 -2
View File
@@ -245,11 +245,12 @@ class Scratch3LooksBlocks {
sayforsecs (args, util) {
this.say(args, util);
const _target = util.target;
return new Promise(resolve => {
this._bubbleTimeout = setTimeout(() => {
this._bubbleTimeout = null;
// Clear say bubble and proceed.
this._updateBubble(util.target, 'say', '');
this._updateBubble(_target, 'say', '');
resolve();
}, 1000 * args.SECS);
});
@@ -261,11 +262,12 @@ class Scratch3LooksBlocks {
thinkforsecs (args, util) {
this.think(args, util);
const _target = util.target;
return new Promise(resolve => {
this._bubbleTimeout = setTimeout(() => {
this._bubbleTimeout = null;
// Clear say bubble and proceed.
this._updateBubble(util.target, 'think', '');
this._updateBubble(_target, 'think', '');
resolve();
}, 1000 * args.SECS);
});