forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Summary
In the meshV2 extension, when a broadcast message is received from the mesh network, it might not exist in the local Scratch project. Currently, if the message name is not found in the project's variables, the broadcast is ignored, and the message doesn't appear in the block dropdowns.
Current Behavior
src/extensions/scratch3_mesh_v2/mesh-service.js#broadcastEventtriggersevent_broadcastopcode with a message name.Scratch3EventBlocks.broadcast(insrc/blocks/scratch3_event.js) useslookupBroadcastMsg.- If
lookupBroadcastMsgreturns null (because the message was never created locally), no hats are started. - The received message is not selectable in "when I receive [message]" or "broadcast [message]" block dropdowns because it doesn't exist in
stage.variables.
Expected Behavior
- When a broadcast message is received via meshV2, if it doesn't exist locally, it should be created automatically on the stage.
- The new message should be selectable in the broadcast block dropdowns.
- The
event_broadcastopcode should be able to trigger the hats for the newly created message.
Proposed Fix
In MeshV2Service (likely in handleBatchEvent or broadcastEvent), add logic to ensure the broadcast message exists:
- Get the stage target:
const stage = this.runtime.getTargetForStage(); - Check if the message exists:
let broadcastVar = stage.lookupBroadcastMsg(null, event.name); - If it doesn't exist:
- Create it:
stage.createVariable(null, event.name, Variable.BROADCAST_MESSAGE_TYPE); - Get the newly created variable:
broadcastVar = stage.lookupBroadcastMsg(null, event.name); - Notify the GUI to refresh blocks:
this.runtime.requestBlocksUpdate();
- Create it:
- Use the
idfrombroadcastVarin theargspassed toevent_broadcast.
Locations to modify
src/extensions/scratch3_mesh_v2/mesh-service.js
References
- Broadcast message type:
Variable.BROADCAST_MESSAGE_TYPE('broadcast_msg')
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels