Broadcast message functionality (works with creating new messages, and switching back and forth between them as well). This commit includes a temporary workaround for the issue where the default broadcast message, 'message1' wasn't triggering a var_create event (filed in LLK/scratch-blocks#1258).

This commit is contained in:
Karishma Chadha 2017-11-21 16:48:48 -05:00
parent d5acdbe983
commit 0a15190b85
5 changed files with 52 additions and 4 deletions

View file

@ -92,6 +92,23 @@ class Target extends EventEmitter {
return newVariable;
}
/**
* Look up a broadcast message object, and create it if one doesn't exist.
* @param {string} id Id of the variable.
* @param {string} name Name of the variable.
* @return {!Variable} Variable object.
*/
lookupOrCreateBroadcastMsg (id, name) {
debugger;
const broadcastMsg = this.lookupVariableById(id);
if (broadcastMsg) return broadcastMsg;
// No variable with this name exists - create it locally.
const newBroadcastMsg = new Variable(id, name,
Variable.BROADCAST_MESSAGE_TYPE, false);
this.variables[id] = newBroadcastMsg;
return newBroadcastMsg;
}
/**
* Look up a variable object.
* Search begins for local variables; then look for globals.
@ -134,7 +151,7 @@ class Target extends EventEmitter {
* dictionary of variables.
* @param {string} id Id of variable
* @param {string} name Name of variable.
* @param {string} type Type of variable, '' or 'list'
* @param {string} type Type of variable, '', 'broadcast_msg', or 'list'
*/
createVariable (id, name, type) {
if (!this.variables.hasOwnProperty(id)) {