From e13120da3f506de3b6da0255de91754bbb76386e Mon Sep 17 00:00:00 2001 From: djdolphin Date: Sun, 8 Jun 2014 13:58:21 -0400 Subject: [PATCH 1/5] Made attribute block update when switching sprite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the sprite you switch to doesn’t have an attribute or variable, it will set the attribute to the default one for sprites or the stage. --- src/scratch/BlockMenus.as | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scratch/BlockMenus.as b/src/scratch/BlockMenus.as index 9de0191..d8d2af1 100644 --- a/src/scratch/BlockMenus.as +++ b/src/scratch/BlockMenus.as @@ -402,6 +402,13 @@ public class BlockMenus implements DragClient { else if (s == 'myself') blockArg.setArgValue('_myself_', Translator.map('myself')); else if (s == 'Stage') blockArg.setArgValue('_stage_', Translator.map('Stage')); else blockArg.setArgValue(s); + if (block.op == 'getAttribute:of:') { + var obj:ScratchObj = app.stagePane.objNamed(s); + var attr:String = block.args[0].argValue; + var allowedAttrs:Array = obj.isStage ? ['backdrop #', 'background #', 'backdrop name', 'volume'] : + ['x position', 'y position', 'direction', 'costume #', 'costume name', 'size', 'volume']; + if ((allowedAttrs.indexOf(attr) == -1) && (obj.varNames().indexOf(attr) == -1)) block.args[0].setArgValue(obj.isStage ? 'backdrop #' : 'x position'); + } Scratch.app.setSaveNeeded(); } var spriteNames:Array = []; From 8267f2415554a785b2cdd85e9346eecbce8cbeec Mon Sep 17 00:00:00 2001 From: djdolphin Date: Sun, 8 Jun 2014 14:05:17 -0400 Subject: [PATCH 2/5] Shortened the code a little --- src/scratch/BlockMenus.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scratch/BlockMenus.as b/src/scratch/BlockMenus.as index d8d2af1..a1a8c1d 100644 --- a/src/scratch/BlockMenus.as +++ b/src/scratch/BlockMenus.as @@ -407,7 +407,7 @@ public class BlockMenus implements DragClient { var attr:String = block.args[0].argValue; var allowedAttrs:Array = obj.isStage ? ['backdrop #', 'background #', 'backdrop name', 'volume'] : ['x position', 'y position', 'direction', 'costume #', 'costume name', 'size', 'volume']; - if ((allowedAttrs.indexOf(attr) == -1) && (obj.varNames().indexOf(attr) == -1)) block.args[0].setArgValue(obj.isStage ? 'backdrop #' : 'x position'); + if ((allowedAttrs.indexOf(attr) == -1) && !obj.ownsVar(attr)) block.args[0].setArgValue(obj.isStage ? 'backdrop #' : 'x position'); } Scratch.app.setSaveNeeded(); } From 92d77bc6e37758c5731023103677a6af5ccaca85 Mon Sep 17 00:00:00 2001 From: djdolphin Date: Mon, 9 Jun 2014 07:04:15 -0400 Subject: [PATCH 3/5] Changed "allowed" to "valid" I think it makes a little more sense. --- src/scratch/BlockMenus.as | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scratch/BlockMenus.as b/src/scratch/BlockMenus.as index a1a8c1d..0a7ea1e 100644 --- a/src/scratch/BlockMenus.as +++ b/src/scratch/BlockMenus.as @@ -405,9 +405,9 @@ public class BlockMenus implements DragClient { if (block.op == 'getAttribute:of:') { var obj:ScratchObj = app.stagePane.objNamed(s); var attr:String = block.args[0].argValue; - var allowedAttrs:Array = obj.isStage ? ['backdrop #', 'background #', 'backdrop name', 'volume'] : + var validAttrs:Array = obj.isStage ? ['backdrop #', 'background #', 'backdrop name', 'volume'] : ['x position', 'y position', 'direction', 'costume #', 'costume name', 'size', 'volume']; - if ((allowedAttrs.indexOf(attr) == -1) && !obj.ownsVar(attr)) block.args[0].setArgValue(obj.isStage ? 'backdrop #' : 'x position'); + if ((validAttrs.indexOf(attr) == -1) && !obj.ownsVar(attr)) block.args[0].setArgValue(obj.isStage ? 'backdrop #' : 'x position'); } Scratch.app.setSaveNeeded(); } From 0c7de21dc3b1092d055b9bf294280a64431f856b Mon Sep 17 00:00:00 2001 From: djdolphin Date: Mon, 9 Jun 2014 13:09:33 -0400 Subject: [PATCH 4/5] Use translated default values --- src/scratch/BlockMenus.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scratch/BlockMenus.as b/src/scratch/BlockMenus.as index 0a7ea1e..4de0a64 100644 --- a/src/scratch/BlockMenus.as +++ b/src/scratch/BlockMenus.as @@ -407,7 +407,7 @@ public class BlockMenus implements DragClient { var attr:String = block.args[0].argValue; var validAttrs:Array = obj.isStage ? ['backdrop #', 'background #', 'backdrop name', 'volume'] : ['x position', 'y position', 'direction', 'costume #', 'costume name', 'size', 'volume']; - if ((validAttrs.indexOf(attr) == -1) && !obj.ownsVar(attr)) block.args[0].setArgValue(obj.isStage ? 'backdrop #' : 'x position'); + if ((validAttrs.indexOf(attr) == -1) && !obj.ownsVar(attr)) block.args[0].setArgValue(obj.isStage ? Translator.map('backdrop #') : Translator.map('x position')); } Scratch.app.setSaveNeeded(); } From 872e7ab45092b9af8808718c9c2b31e0531706f1 Mon Sep 17 00:00:00 2001 From: djdolphin Date: Mon, 9 Jun 2014 14:03:30 -0400 Subject: [PATCH 5/5] Revert "Use translated default values" This reverts commit 0c7de21dc3b1092d055b9bf294280a64431f856b. --- src/scratch/BlockMenus.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scratch/BlockMenus.as b/src/scratch/BlockMenus.as index 4de0a64..0a7ea1e 100644 --- a/src/scratch/BlockMenus.as +++ b/src/scratch/BlockMenus.as @@ -407,7 +407,7 @@ public class BlockMenus implements DragClient { var attr:String = block.args[0].argValue; var validAttrs:Array = obj.isStage ? ['backdrop #', 'background #', 'backdrop name', 'volume'] : ['x position', 'y position', 'direction', 'costume #', 'costume name', 'size', 'volume']; - if ((validAttrs.indexOf(attr) == -1) && !obj.ownsVar(attr)) block.args[0].setArgValue(obj.isStage ? Translator.map('backdrop #') : Translator.map('x position')); + if ((validAttrs.indexOf(attr) == -1) && !obj.ownsVar(attr)) block.args[0].setArgValue(obj.isStage ? 'backdrop #' : 'x position'); } Scratch.app.setSaveNeeded(); }