mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-14 15:28:50 -04:00
First cut at turning lists into typed variables
This commit is contained in:
parent
a735459427
commit
70959cc7f5
9 changed files with 55 additions and 80 deletions
src/engine
|
@ -9,19 +9,27 @@ class Variable {
|
|||
/**
|
||||
* @param {string} id Id of the variable.
|
||||
* @param {string} name Name of the variable.
|
||||
* @param {(string|number)} value Value of the variable.
|
||||
* @param {(string|number)} type Type of the variable, one of "" or "list"
|
||||
* @param {boolean} isCloud Whether the variable is stored in the cloud.
|
||||
* @constructor
|
||||
*/
|
||||
constructor (id, name, value, isCloud) {
|
||||
constructor (id, name, type, isCloud) {
|
||||
this.id = id || uid();
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
this.isCloud = isCloud;
|
||||
switch (this.type) {
|
||||
case "":
|
||||
this.value = 0;
|
||||
break;
|
||||
case "list":
|
||||
this.value = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
toXML () {
|
||||
return `<variable type="" id="${this.id}">${this.name}</variable>`;
|
||||
return `<variable type="${this.type}" id="${this.id}">${this.name}</variable>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue