mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-26 22:30:27 -04:00
add getProcedureParamNamesIdsAndDefaults
Use getProcedureParamNamesIdsAndDefaults to get the defaults along with names and ids so defaults may be set for a procedure call if the parameter is not provided.
This commit is contained in:
parent
ca38fb2cc3
commit
2b257dde57
4 changed files with 29 additions and 7 deletions
src/engine
|
@ -230,11 +230,20 @@ class Blocks {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get names of parameters for the given procedure.
|
||||
* Get names and ids of parameters for the given procedure.
|
||||
* @param {?string} name Name of procedure to query.
|
||||
* @return {?Array.<string>} List of param names for a procedure.
|
||||
*/
|
||||
getProcedureParamNamesAndIds (name) {
|
||||
return this.getProcedureParamNamesIdsAndDefaults(name).slice(0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names, ids, and defaults of parameters for the given procedure.
|
||||
* @param {?string} name Name of procedure to query.
|
||||
* @return {?Array.<string>} List of param names for a procedure.
|
||||
*/
|
||||
getProcedureParamNamesIdsAndDefaults (name) {
|
||||
const cachedNames = this._cache.procedureParamNames[name];
|
||||
if (typeof cachedNames !== 'undefined') {
|
||||
return cachedNames;
|
||||
|
@ -247,7 +256,9 @@ class Blocks {
|
|||
block.mutation.proccode === name) {
|
||||
const names = JSON.parse(block.mutation.argumentnames);
|
||||
const ids = JSON.parse(block.mutation.argumentids);
|
||||
this._cache.procedureParamNames[name] = [names, ids];
|
||||
const defaults = JSON.parse(block.mutation.argumentdefaults);
|
||||
|
||||
this._cache.procedureParamNames[name] = [names, ids, defaults];
|
||||
return this._cache.procedureParamNames[name];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue