/** * @fileoverview * Object representing a Scratch variable. */ const uid = require('../util/uid'); class Variable { /** * @param {string} id Id of the variable. * @param {string} name Name of the variable. * @param {string} type Type of the variable, one of '' or 'list' * @param {boolean} isCloud Whether the variable is stored in the cloud. * @constructor */ constructor (id, name, type, isCloud) { this.id = id || uid(); this.name = name; this.type = type; this.isCloud = isCloud; switch (this.type) { case Variable.SCALAR_TYPE: this.value = 0; break; case Variable.LIST_TYPE: this.value = []; break; default: throw new Error(`Invalid variable type: ${this.type}`); } } toXML () { return `${this.name}`; } /** * Type representation for scalar variables. * This is currently represented as '' * for compatibility with blockly. * @const {string} */ static get SCALAR_TYPE () { return ''; } /** * Type representation for list variables. * @const {string} */ static get LIST_TYPE () { return 'list'; } } module.exports = Variable;