forked from sayamindu/scratch-extensions
-
Notifications
You must be signed in to change notification settings - Fork 2
/
alarm_extension.js
44 lines (36 loc) · 1.2 KB
/
alarm_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
37
38
39
40
41
42
43
44
/* Extension demonstrating a hat block */
/* Sayamindu Dasgupta <[email protected]>, May 2014 */
new (function() {
var ext = this;
var alarm_went_off = false; // This becomes true after the alarm goes off
// 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'};
};
ext.set_alarm = function(time) {
window.setTimeout(function() {
alarm_went_off = true;
}, time*1000);
};
ext.when_alarm = function() {
// Reset alarm_went_off if it is true, and return true
// otherwise, return false.
if (alarm_went_off === true) {
alarm_went_off = false;
return true;
}
return false;
};
// Block and block menu descriptions
var descriptor = {
blocks: [
['', 'run alarm after %n seconds', 'set_alarm', '2'],
['h', 'when alarm goes off', 'when_alarm'],
]
};
// Register the extension
ScratchExtensions.register('Alarm extension', descriptor, ext);
})();