[Solved] - How do i load blocks in snap offline startup

Just look inside the block.

in "XML gen&build" project?
i think i know,
Maybe something like
this.parentThatIsA(IDE_Morph).rawOpenBlocksString(readFile(blocks.xml), "user created", true)? (from xml gen&build project, block script : build) But readFile() isnt a command

its been 1 days (this forum, 7 hours for the last reply) and i still dont know how to make a mod

oh well i guess ill not make a offline snap mod
instead i guess i can make a block mod
(add categories blocks idk)
idk what im saying

i guess theres to way how to make offline snap mod

There are, already, many ways to start Snap! with preloaded blocks/projects.
For your purposes, 2 of them may be suitable:

  1. Attach exported blocks (URL-encoded XML) to Snap! URL
    https://snap.berkeley.edu/snap/snap.html#open:%3Cblocks%20app%3D%22Snap!%206%2C%20https%3A%2F%2Fsnap.berkeley.edu%22%20version%3D%221%22%3E%3Cblock-definition%20s%3D%22test1%22%20type%3D%22command%22%20category%3D%22motion%22%3E%3Cheader%3E%3C%2Fheader%3E%3Ccode%3E%3C%2Fcode%3E%3Ctranslations%3E%3C%2Ftranslations%3E%3Cinputs%3E%3C%2Finputs%3E%3Cscript%3E%3Cblock%20s%3D%22turnLeft%22%3E%3Cl%3E15%3C%2Fl%3E%3C%2Fblock%3E%3C%2Fscript%3E%3C%2Fblock-definition%3E%3C%2Fblocks%3E
  2. Attach project URL (CORS or Same Origin must be resolved)
    https://snap.berkeley.edu/snap/snap.html#open:https://myhost/blocks.xml
    In Your case
    https://localhost/snap/snap.html#open:blocks.xml

Thats pretty cool, Also how do i change the icon of the snap! (top left corner) icon image?
image

Probably src\snap_logo_sm.png

Oh thanks, Also

This works well!

Im having another tiny problem, How do i create categories (or, executing javascript) in html?


This way doesn't work :thinking:

Im confused.


Doesnt work ^ but
image
works??
I dont get this.

return this.parent.IDE_Morph

doesn't work. It has to be

return this.parentThatIsA(IDE_Morph);

I even tried that and it didnt work:

That's weird. It works for me.

Maybe its because im in the offline version of snap?

edit: it doesnt even work with the online version, thats weird.

code:

function FuncSpMoPr() {
return SpriteMorph.prototype
};

function FuncIDE() {
return this.parentThatIsA(IDE_Morph);
};

SpMoPr = FuncSpMoPr();
ide = FuncIDE();
name = "Hello";
r = 255;
g = 0;
b = 0;
if(name != "") {
const cats = SpMoPr.categories;
if(!cats.includes(name)) {cats.push(name);};
SpMoPr.blockColor[name] = new Color(r, g, b, 1);
ide.createCategories();
ide.reactToWorldResize(world.bounds.copy());
ide.flushBlocksCache();
ide.refreshPalette();
}

Huh. That's weird. That function is hardcoded into Snap!, it should work on offline and online versions.
Try

ide = FuncIDE.call(this);

Edit: If that worked, then what object did the function call on previously...?

Oh now it worked, Thanks

i tried to implement it into snap.html
and it didnt work
image
heres the html:

so yea you see that i cant put javascripts in the startup of snap.html to make it load categories.
How im gonna do this?

Check the order and scope of script execution. Your function seems to be executed before the Snap's "world" is declared.
Second: according to the Snap sources ("api.js"), the recommended way to get IDE is "world.children[0]".

like this?
image

Well i tried it and didn't work:
image

So which way it is?

Rather something like

function FuncSpMoPr() {
return SpriteMorph.prototype
};

function addCategories(){
SpMoPr = FuncSpMoPr();
ide = world.children[9];
name = "Hello";
r = 255;
g = 0;
b = 0;
if(name != "") {
 const cats = SpMoPr.categories;
 if(!cats.includes(name)) {cats.push(name);};
 SpMoPr.blockColor[name] = new Color(r, g, b, 1);
 ide.createCategories();
 ide.reactToWorldResize(world.bounds.copy());
 ide.flushBlocksCache();
 ide.refreshPalette();
}}

snap.html
 <script>
            var world;
            window.onload = function () {
                world = new WorldMorph(document.getElementById('world'));
                new IDE_Morph().openIn(world);
                /********************/
                addCategories();
                /********************/
                loop();
....

im i doing this wrong or is this just a bug?


image
image