mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
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:
parent
d5acdbe983
commit
0a15190b85
5 changed files with 52 additions and 4 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue