Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying and pasting (⌘C / ⌘V) blocks between sprites can cause local variables to share the same ID. #3963

Open
Wowfunhappy opened this issue Apr 1, 2023 · 1 comment

Comments

@Wowfunhappy
Copy link

Wowfunhappy commented Apr 1, 2023

Expected Behavior

No two distinct variables in a given project should have the same ID.

Actual Behavior

Two different local variables in different sprites can share a single ID. This interferes with monitors. Although each sprite can independently access and modify their own copy of the variable (changing the variable in one sprite doesn't change it in the other sprite), the user will only be able to show one of the two variable monitors.

Steps to Reproduce

  1. Create a new project
  2. Create a variable "for this sprite only"
  3. Drag a block which uses your new variable (e.g. set foo to 0) onto the workspace.
  4. Add a second sprite.
  5. Select your first sprite. Click the block you added to the workspace in step 3, and copy it to your clipboard with ⌘C. (Presumably this would be ctrl+C on Windows/Linux?)
  6. Select your second sprite. Paste the block you copied with ⌘V (or ctrl+V, etc).

Operating System and Browser

Mac OS X, Chromium 111.


This may be a duplicate of #2429, but that issue seems to be caused by some sort of race condition in very large projects . By contrast, the problem described above can be easily replicated in projects of any size, and I've had it come up frequently while teaching students in schools.

Notably, if you drag your block between sprites (share the love) instead of using ⌘C and ⌘V, the new local variable will be created properly. It's merely copying and pasting that causes problems.

Where is the code responsible for fixing variables that are dragged between sprites, and could that same code be applied to pasting?

P.S. See also: #1766, #1375

@Wowfunhappy Wowfunhappy changed the title Copying and pasting (⌘C / ⌘V) blocks between sprites can cause local variables to share the same ID Copying and pasting (⌘C / ⌘V) blocks between sprites can cause local variables to share the same ID. Apr 2, 2023
@Wowfunhappy
Copy link
Author

Wowfunhappy commented Apr 2, 2023

Where is the code responsible for fixing variables that are dragged between sprites, and could that same code be applied to pasting?

Okay, so I've at least found the answer to that question:

scratchfoundation/scratch-gui@07a679d
https://github.com/LLK/scratch-vm/blob/develop/src/virtual-machine.js#L1240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant