scratchfoundation / scratch-blocks

Scratch Blocks is a library for building creative computing interfaces.
https://scratch.mit.edu/developers
Apache License 2.0
2.57k stars 1.37k forks source link

Undefined variable appears when deleting variable and changing sprites #1215

Closed fsih closed 6 years ago

fsih commented 6 years ago

Expected Behavior

No undefined variables

Actual Behavior

undefined variable appears

Steps to Reproduce

  1. Go to Data. Create a variable.
  2. Drag "set x to" block to workspace
  3. In the dropdown, delete variable You can also delete variables by right clicking on them in the flyout and choosing delete

all appears well

  1. Add a new sprite or change to the costume tab
  2. Return to the first sprite or the blocks tab

There is now a variable called "undefined"

Operating System and Browser

Windows 10 Chrome

paulkaplan commented 6 years ago

The reason this is happening is because the monitored block for the variable reporter is not being deleted when the variable is deleted. The VM is actually running the opcode for getVariable, which runs a lookupOrCreateVariable, emphasis on the Create part. The variable was deleted but then re-created. vm/scratch3_data.js only passes the variable ID to lookupOrCreateVariable, which is what causes the variable name to appear as undefined.

paulkaplan commented 6 years ago

@fsih we should move this issue to VM because it is only a vm problem, not scratch-blocks.

fsih commented 6 years ago

Moved to https://github.com/LLK/scratch-vm/issues/775. Thanks for investigating!