From d267b696af1e7a429c4b31dc87b46dc638c3509f Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 14 May 2013 16:16:21 +0200 Subject: Broadcast & Message enhancements, fixed #93 * When I receive option * getLastMessage reporter + watcher --- objects.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 5b03f2d..086b1f6 100644 --- a/objects.js +++ b/objects.js @@ -532,6 +532,11 @@ SpriteMorph.prototype.initBlocks = function () { category: 'control', spec: 'broadcast %msg and wait' }, + getLastMessage: { + type: 'reporter', + category: 'control', + spec: 'message' + }, doWait: { type: 'command', category: 'control', @@ -1539,6 +1544,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('doBroadcast')); blocks.push(block('doBroadcastAndWait')); + blocks.push(watcherToggle('getLastMessage')); + blocks.push(block('getLastMessage')); blocks.push('-'); blocks.push(block('doWarp')); blocks.push('-'); @@ -2719,7 +2726,7 @@ SpriteMorph.prototype.allMessageNames = function () { morph.selector )) { txt = morph.inputs()[0].evaluate(); - if (txt !== '') { + if (isString(txt) && txt !== '') { if (!contains(msgs, txt)) { msgs.push(txt); } @@ -2732,9 +2739,11 @@ SpriteMorph.prototype.allMessageNames = function () { SpriteMorph.prototype.allHatBlocksFor = function (message) { return this.scripts.children.filter(function (morph) { + var event; if (morph.selector) { if (morph.selector === 'receiveMessage') { - return morph.inputs()[0].evaluate() === message; + event = morph.inputs()[0].evaluate(); + return event === message || (event instanceof Array); } if (morph.selector === 'receiveGo') { return message === '__shout__go__'; @@ -2794,6 +2803,16 @@ SpriteMorph.prototype.getTempo = function () { return 0; }; +// SpriteMorph last message + +SpriteMorph.prototype.getLastMessage = function () { + var stage = this.parentThatIsA(StageMorph); + if (stage) { + return stage.getLastMessage(); + } + return ''; +}; + // SpriteMorph user prompting SpriteMorph.prototype.getLastAnswer = function () { @@ -3189,6 +3208,7 @@ StageMorph.prototype.init = function (globals) { this.timerStart = Date.now(); this.tempo = 60; // bpm + this.lastMessage = ''; this.watcherUpdateFrequency = 2; this.lastWatcherUpdate = Date.now(); @@ -3436,6 +3456,12 @@ StageMorph.prototype.getTempo = function () { return +this.tempo; }; +// StageMorph messages + +StageMorph.prototype.getLastMessage = function () { + return this.lastMessage || ''; +}; + // StageMorph drag & drop StageMorph.prototype.wantsDropOf = function (aMorph) { @@ -3767,6 +3793,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('doBroadcast')); blocks.push(block('doBroadcastAndWait')); + blocks.push(watcherToggle('getLastMessage')); + blocks.push(block('getLastMessage')); blocks.push('-'); blocks.push(block('doWarp')); blocks.push('-'); @@ -5417,7 +5445,10 @@ WatcherMorph.prototype.object = function () { }; WatcherMorph.prototype.isGlobal = function (selector) { - return contains(['getTimer', 'getLastAnswer', 'getTempo'], selector); + return contains( + ['getTimer', 'getLastAnswer', 'getTempo', 'getLastMessage'], + selector + ); }; // WatcherMorph slider accessing: -- cgit v1.3.1