-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_wait_extension.js
36 lines (30 loc) · 1.07 KB
/
random_wait_extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Extension demonstrating a blocking command block */
/* Sayamindu Dasgupta <[email protected]>, May 2014 */
new (function() {
var ext = this;
// Cleanup function when the extension is unloaded
ext._shutdown = function() {};
// Status reporting code
// Use this to report missing hardware, plugin or unsupported browser
ext._getStatus = function() {
return {status: 2, msg: 'Ready'};
};
// Functions for block with type 'w' will get a callback function as the
// final argument. This should be called to indicate that the block can
// stop waiting.
ext.wait_random = function(callback) {
wait = Math.random();
console.log('Waiting for ' + wait + ' seconds');
window.setTimeout(function() {
callback();
}, wait*1000);
};
// Block and block menu descriptions
var descriptor = {
blocks: [
['w', 'wait for random time', 'wait_random'],
]
};
// Register the extension
ScratchExtensions.register('Random wait extension', descriptor, ext);
})();