mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-03 00:54:57 -04:00
Extend getSubstack to support multiple substacks
This commit is contained in:
parent
9be33089a8
commit
dbb31462ad
1 changed files with 10 additions and 3 deletions
|
@ -50,14 +50,21 @@
|
||||||
/**
|
/**
|
||||||
* Get the substack for a particular C-shaped block
|
* Get the substack for a particular C-shaped block
|
||||||
* @param {?string} id ID for block to get the substack for
|
* @param {?string} id ID for block to get the substack for
|
||||||
|
* @param {?number} substackNum Which substack to select (e.g. for if-else)
|
||||||
* @return {?string} ID of block in the substack
|
* @return {?string} ID of block in the substack
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getSubstack = function (id) {
|
Blocks.prototype.getSubstack = function (id, substackNum) {
|
||||||
var block = this._blocks[id];
|
var block = this._blocks[id];
|
||||||
if (typeof block === 'undefined') return null;
|
if (typeof block === 'undefined') return null;
|
||||||
|
|
||||||
|
var inputName = 'SUBSTACK';
|
||||||
|
if (substackNum > 0) {
|
||||||
|
inputName += substackNum;
|
||||||
|
}
|
||||||
|
|
||||||
// Empty C-block?
|
// Empty C-block?
|
||||||
if (!('SUBSTACK' in block.inputs)) return null;
|
if (!(inputName in block.inputs)) return null;
|
||||||
return block.inputs['SUBSTACK'].block;
|
return block.inputs[inputName].block;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue