scratch-vm/src/engine/variable.js

37 lines
888 B
JavaScript
Raw Normal View History

/**
* @fileoverview
* Object representing a Scratch variable.
*/
const uid = require('../util/uid');
2017-04-17 19:42:48 -04:00
class Variable {
/**
* @param {string} id Id of the variable.
* @param {string} name Name of the variable.
* @param {(string|number)} type Type of the variable, one of "" or "list"
2017-04-17 19:42:48 -04:00
* @param {boolean} isCloud Whether the variable is stored in the cloud.
* @constructor
*/
constructor (id, name, type, isCloud) {
this.id = id || uid();
2017-04-17 19:42:48 -04:00
this.name = name;
this.type = type;
2017-04-17 19:42:48 -04:00
this.isCloud = isCloud;
switch (this.type) {
case "":
this.value = 0;
break;
case "list":
this.value = [];
break;
}
2017-04-17 19:42:48 -04:00
}
toXML () {
return `<variable type="${this.type}" id="${this.id}">${this.name}</variable>`;
}
2017-04-17 19:42:48 -04:00
}
module.exports = Variable;