Skip to content

Register missing broadcasts when importing a sprite - #7

Merged
Mistium merged 1 commit into
developfrom
fix/sprite-import-broadcasts
Jul 14, 2026
Merged

Register missing broadcasts when importing a sprite#7
Mistium merged 1 commit into
developfrom
fix/sprite-import-broadcasts

Conversation

@Mistium

@Mistium Mistium commented Jul 14, 2026

Copy link
Copy Markdown
Member

Fixes #3.

When a sprite is imported (vm.addSprite), installTargets calls fixUpVariableReferences() to merge or create any global variables the sprite's blocks reference, but it fetched references without the optIncludeBroadcast flag, so BROADCAST_OPTION fields were skipped and the broadcast variable was never created on the stage. Broadcast blocks bail silently when lookupBroadcastMsg finds nothing. In the editor, scratch-blocks masks this by creating the variable during workspace load, which is why "see inside" made the project work.

The fix passes the broadcast flag so broadcast references flow through the same machinery as variables and lists: a broadcast whose name already exists on the stage gets its block fields re-pointed to the existing variable's id, and a new broadcast is created on the stage under the imported id. The _broadcastCleanupNeeded sweep only deletes broadcasts no block references, so the new ones survive.

Compared to the PenguinMod fix linked in the issue, this also handles the event_whenbroadcastreceived hat field, merges with existing same-named broadcasts instead of creating duplicates, and covers sprite2 imports.

Added a unit test covering both paths (merge with existing broadcast, create missing one); test/unit/engine_target.js passes 35/35.

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Sprite imports run fixUpVariableReferences to merge or create global
variables referenced by the sprite's blocks, but broadcast fields were
excluded, so broadcasts from an imported sprite only worked after the
editor workspace recreated them. Include BROADCAST_OPTION fields so
broadcasts merge with existing same-named ones or get created on the
stage, headless included.

Fixes #3

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Mistium
Mistium merged commit 2b0eaa3 into develop Jul 14, 2026
0 of 2 checks passed
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

Successfully merging this pull request may close these issues.

importing sprite does not register broadcast unless in editor

1 participant