Scratch-gui: Variables don't persist

Created on 9 May 2017  路  3Comments  路  Source: LLK/scratch-gui

Expected Behavior

_Please describe what should happen_
After creating a global variable, it should be available for all sprites.

Actual Behavior

_Describe what actually happens_
The variable disappears after switching to another sprite.

Steps to Reproduce

_Explain what someone needs to do in order to see what's described in Actual behavior above_

  1. Go to https://llk.github.io/scratch-gui/
  2. Add a new sprite, for the "A"
  3. Switch to the cat, and add a new variable.
  4. Switch to the "A" - the variable is gone.
  5. Switch back to the cat - the variable is still gone.

Note that this is not broken on http://llk.github.io/scratch-vm/

bug

All 3 comments

@rschamp Appears to be related to calling workspace.toolbox_.refreshSelection(), which we are doing on workspace update https://github.com/LLK/scratch-gui/blob/075216f585770f74a189ddaff66ac75a39c2308d/src/containers/blocks.jsx#L122

The git blame for that lines indicates it is being called because the sound dropdown menus wouldn't update for sprite changes.

@paulkaplan and I looked into this, here is what happens:

  • When switching sprites, the workspace is cleared (https://github.com/LLK/scratch-gui/blob/075216f585770f74a189ddaff66ac75a39c2308d/src/containers/blocks.jsx#L117) which clears workspace.variableList

  • The variable list is rebuilt during ScratchBlocks.Xml.domToWorkspace using the xml from the VM. Thus it only finds and restores the variables that are used in that workspace (so if you use the variable, in step 5 above, it will be restored on the cat)

Instead of parsing out of the xml, scratch blocks needs to get the list of variables from the VM.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thisandagain picture thisandagain  路  4Comments

Richienb picture Richienb  路  3Comments

kyleplo picture kyleplo  路  4Comments

MrBlockCat picture MrBlockCat  路  4Comments

ntlrsk picture ntlrsk  路  3Comments