From dce0f5e871ff61a09fb80700f9eb31b89ee7b5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Tue, 11 Jul 2017 08:55:37 +0200 Subject: [PATCH] fixed variable inheritance for traditional Scratch-like clones --- history.txt | 1 + objects.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/history.txt b/history.txt index ebf2097a..86a78ab1 100755 --- a/history.txt +++ b/history.txt @@ -3523,6 +3523,7 @@ Fixes: 170711 ------ * Objects: fixed an inheritance glitch for clones +* Objects: fixed variable inheritance for traditional Scratch-like clones diff --git a/objects.js b/objects.js index ef4cad8d..5364a7a2 100644 --- a/objects.js +++ b/objects.js @@ -1442,8 +1442,6 @@ SpriteMorph.prototype.fullCopy = function (forClone) { c.color = this.color.copy(); c.blocksCache = {}; c.paletteCache = {}; - c.variables = this.variables.copy(); - c.variables.owner = c; arr = []; this.inheritedAttributes.forEach(function (att) { arr.push(att); @@ -1451,6 +1449,11 @@ SpriteMorph.prototype.fullCopy = function (forClone) { c.inheritedAttributes = arr; if (forClone) { c.exemplar = this; + c.variables = new VariableFrame(null, c); + c.variables.parentFrame = this.variables; + c.inheritedVariableNames().forEach(function (name) { + c.shadowVar(name, c.variables.getVar(name)); + }); this.addSpecimen(c); this.cachedPropagation = false; ['scripts', 'costumes', 'sounds'].forEach(function (att) { @@ -1459,6 +1462,8 @@ SpriteMorph.prototype.fullCopy = function (forClone) { } }); } else { + c.variables = this.variables.copy(); + c.variables.owner = c; c.scripts = this.scripts.fullCopy(); c.customBlocks = []; this.customBlocks.forEach(function (def) { @@ -5255,10 +5260,10 @@ SpriteMorph.prototype.setExemplar = function (another) { this.emancipate(); this.exemplar = another; if (another) { - this.variables.parentFrame = (another.variables); + this.variables.parentFrame = another.variables; another.addSpecimen(this); } else { - this.variables.parentFrame = (this.globalVariables()); + this.variables.parentFrame = this.globalVariables(); } if (ide) { ide.flushBlocksCache('variables'); @@ -8910,7 +8915,7 @@ WatcherMorph.prototype.update = function () { xPosition: 'x position', yPosition: 'y position', direction: 'direction', - getCostumeIdx: 'costume #', //+++ + getCostumeIdx: 'costume #', getScale: 'size'} [this.getter]; isGhosted = att ? this.target.inheritsAttribute(att) : false; }