Wait until scene loads to run code block


When using multiple tabs of blockly code, I have an issue where events in the second tab are not being registered until the code in the first tab finishes running. A portion of that code runs some transitions and pauses that take time to run.

I know this is solvable by including the event blocks above the code in the first tab, but was wondering if there is any other workaround so I can keep the tabs organized a certain way? I don’t see any block for “after load of scene” so that the events will register before the transitions run (similar to the JavaScript function document.onload). Is there a way to utilize the coding block or other blocks to accomplish this in place of pure JavaScript?


Hi Sean,

like you already said, at the moment you need to define these event listeners at the top of the first Blockly script because of the way how synchronous Blockly in CoSpaces Edu works.

But we are working on an importing/exporting feature which will make it possible to export a variable or function in one script and import it in another script and use it there. This will make it easier to organize your code.

I’m not sure about an onload event listener in the context of a Blockly script in CoSpaces. This is different from document.onload which is mostly used to prevent executing certain JavaScript before the browser has build the DOM tree. But it’s an interesting idea and I’ll talk to the team.