Error when syncing Scratch blocks

37 views
Skip to first unread message

Quantiset

unread,
May 30, 2024, 8:17:01 AMMay 30
to Blockly
Hello, i'm working on a project where I'm trying to sync blocks in Scratch, sorta like the Blocklive extension on the Chrome extensions. However, when I run an event, it (most of the time) says that "Workspace is null. Event must have been generated from real Blockly events". I tracked that down to the getEventWorkspace_ function. However, when I check the workspace id of the class and compare it to scratch's workspace through ScratchBlocks's workspace id, it says they're the same.

Interestingly, it *sometimes* works one way. If the later connected person joins, it doesn't say this if he submits data but it will if he recieves any. I have no idea what the issue could be

Here is my code:
let data = JSON.parse(message.data);
        if (data.uid == nid) {
            console.log("discarding");
            return;
        }

        console.log(message, "recieved")
       
        let ogTarget = this.props.vm.editingTarget;
       
        this.props.vm.editingTarget = this.props.vm.runtime.getSpriteTargetByName(data.target);
        this.props.vm.runtime._editingTarget = this.props.vm.editingTarget;
       
        const event = this.ScratchBlocks.Events.fromJson(data.event, this.workspace);

        const qselect = document.querySelector('.blocklyWorkspace');

        try {
            stopEmission = true;
            if (!!qselect) {
                console.log(event.workspaceId);
                console.log(this.workspace.id);
                event.run(true);
            } else {
                let vevent = data.ogevent;
                vevent.xml = data.xml;
                this.props.vm.editingTarget.blocks.blocklyListen(vevent);
            }    
        } catch (e) {
            console.error(e);
        }

        this.props.vm.editingTarget = ogTarget;
        this.props.vm.runtime._editingTarget = this.props.vm.editingTarget;

        stopEmission = false;

Christopher Allen

unread,
May 30, 2024, 6:30:39 PMMay 30
to blo...@googlegroups.com
Hi Quantiset,

Hello, i'm working on a project where I'm trying to sync blocks in Scratch, sorta like the Blocklive extension on the Chrome extensions.

Cool.  By the way, have you seen our Blockly real time communication example?
 
However, when I run an event, it (most of the time) says that "Workspace is null. Event must have been generated from real Blockly events". I tracked that down to the getEventWorkspace_ function. However, when I check the workspace id of the class and compare it to scratch's workspace through ScratchBlocks's workspace id, it says they're the same.

There have been a number of divergences between Blockly and Scratch Blocks (which is based on a ~2017 fork of Blockly), and I'm not personally very familiar with the latter, but I will attempt to answer your question nevertheless:

So, proximately, that error will occur if the Event's  .workspaceID does not appear in Blockly.Workspace.WorkspaceDB_ used by Workspace.getById.  You say that the IDs do match, so the question is: does the local Workspace instance have its .id correctly recorded in .WorkspaceDB_, or has something happened to modify its .id after registration, or to delete or modify the relevant entry in the DB?

Interestingly, it *sometimes* works one way. If the later connected person joins, it doesn't say this if he submits data but it will if he recieves any. I have no idea what the issue could be

That is strange indeed.

It should be reasonably straightforward to see what is going on if you inspect the .workspaceID of the event(s), the .ids of the source and destination workspaces, and the contents of Blockly.Workspace.WorkspaceDB_ on the destination instance.


Christopher

Reply all
Reply to author
Forward
0 new messages