Skip to content

Let wait, sayforsecs, thinkforsecs - handle big numbers #1442

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

Closed
wants to merge 3 commits into from
Closed
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: 3 additions & 2 deletions src/blocks/scratch3_control.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Cast = require('../util/cast');
const MathUtil = require('../util/math-util.js');

class Scratch3ControlBlocks {
constructor (runtime) {
Expand Down Expand Up @@ -108,11 +109,11 @@ class Scratch3ControlBlocks {
}

wait (args) {
const duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION));
const duration = 1000 * Cast.toNumber(args.DURATION);
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, duration);
}, MathUtil.clamp(duration, 0, Math.pow(2, 31) - 1)); // setTimeout only supports up to 2^31 - 1
});
}

Expand Down
5 changes: 3 additions & 2 deletions src/blocks/scratch3_looks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Cast = require('../util/cast');
const MathUtil = require('../util/math-util.js');
const Clone = require('../util/clone');
const RenderedTarget = require('../sprites/rendered-target');
const uid = require('../util/uid');
Expand Down Expand Up @@ -309,7 +310,7 @@ class Scratch3LooksBlocks {
this._updateBubble(target, 'say', '');
}
resolve();
}, 1000 * args.SECS);
}, MathUtil.clamp(1000 * args.SECS, 0, Math.pow(2, 31) - 1)); // setTimeout only supports up to 2^31 - 1
});
}

Expand All @@ -329,7 +330,7 @@ class Scratch3LooksBlocks {
this._updateBubble(target, 'think', '');
}
resolve();
}, 1000 * args.SECS);
}, MathUtil.clamp(1000 * args.SECS, 0, Math.pow(2, 31) - 1)); // setTimeout only supports up to 2^31 - 1
});
}

Expand Down