Discuss Scratch

MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

I've looked everywhere on google and found absolutely nothing helpful. I know how to edit the project JSON but whenever I edit a block it doesn't change. It stays the same. Does anyone have useful information on this topic?
BigNate469
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

The list of opcodes on the Wiki may be helpful.

What are you changing, and how?
MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

BigNate469 wrote:

The list of opcodes on the Wiki may be helpful.

What are you changing, and how?
Well one thing I tried is changing the value for move steps to something like a word or just Infinity. I also tried a bunch of other stuff but nothing seemed to change.
move [Infinity] steps
BigNate469
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

MineTurte wrote:

BigNate469 wrote:

The list of opcodes on the Wiki may be helpful.

What are you changing, and how?
Well one thing I tried is changing the value for move steps to something like a word or just Infinity. I also tried a bunch of other stuff but nothing seemed to change.
move [Infinity] steps
Which value in the inputs object did you change?

For example, with a “wait () secs” block,
"tZiEX|~fh=fF^1l_Uf`+": {
    "opcode":"control_wait",
    "next":null,
    "parent":null,
    "inputs":{
        "DURATION":[
            1,
            [
                5,
                "42"
            ]
        ]
    },
    "fields":{},
    "shadow":false,
    "topLevel":true,
    "x":399,
    "y":271
}
changing where it says “42” will change the input of the block. Changing the “5” or “1” before it will make the project fail to load

Last edited by BigNate469 (Oct. 1, 2024 16:04:10)

MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

BigNate469 wrote:

MineTurte wrote:

BigNate469 wrote:

The list of opcodes on the Wiki may be helpful.

What are you changing, and how?
Well one thing I tried is changing the value for move steps to something like a word or just Infinity. I also tried a bunch of other stuff but nothing seemed to change.
move [Infinity] steps
Which value in the inputs object did you change?

For example, with a “wait () secs” block,
"tZiEX|~fh=fF^1l_Uf`+": {
    "opcode":"control_wait",
    "next":null,
    "parent":null,
    "inputs":{
        "DURATION":[
            1,
            [
                5,
                "42"
            ]
        ]
    },
    "fields":{},
    "shadow":false,
    "topLevel":true,
    "x":399,
    "y":271
}
changing where it says “42” will change the input of the block. Changing the “5” or “1” before it will make the project fail to load
I figured out one of my problems. Apparently the JSON file wasn't properly saving and literally just stayed the same. New problem though, a lot of things cause the project to fail to load. Such as changing the key in “When key pressed”. I tried enter, even just “a” but both failed to load.


Actually even just opening the JSON and closing it causes it to no longer load

Last edited by MineTurte (Oct. 1, 2024 16:15:10)

BigNate469
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

MineTurte wrote:

BigNate469 wrote:

snip
I figured out one of my problems. Apparently the JSON file wasn't properly saving and literally just stayed the same. New problem though, a lot of things cause the project to fail to load. Such as changing the key in “When key pressed”. I tried enter, even just “a” but both failed to load.
Hmm.

In the actual when key pressed block (opcode is sensing_keypressed), it points to another block, usually listed right after it, that has an opcode of sensing_keyoptions. Change the value in the sensing_keyoptions blocks rather than in the keypressed block itself- otherwise Scratch will think you're looking for a block (internally) named “a” rather than a key named “a”
MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

BigNate469 wrote:

MineTurte wrote:

BigNate469 wrote:

snip
I figured out one of my problems. Apparently the JSON file wasn't properly saving and literally just stayed the same. New problem though, a lot of things cause the project to fail to load. Such as changing the key in “When key pressed”. I tried enter, even just “a” but both failed to load.
Hmm.

In the actual when key pressed block (opcode is sensing_keypressed), it points to another block, usually listed right after it, that has an opcode of sensing_keyoptions. Change the value in the sensing_keyoptions blocks rather than in the keypressed block itself- otherwise Scratch will think you're looking for a block (internally) named “a” rather than a key named “a”
Well it appears as if my method of editing the JSON doesn't work properly as even not changing the JSON at all and just passing it through the editor causes it to fail to load. Kinda stuck at this point lol
BigNate469
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

MineTurte wrote:

BigNate469 wrote:

MineTurte wrote:

BigNate469 wrote:

snip
I figured out one of my problems. Apparently the JSON file wasn't properly saving and literally just stayed the same. New problem though, a lot of things cause the project to fail to load. Such as changing the key in “When key pressed”. I tried enter, even just “a” but both failed to load.
Hmm.

In the actual when key pressed block (opcode is sensing_keypressed), it points to another block, usually listed right after it, that has an opcode of sensing_keyoptions. Change the value in the sensing_keyoptions blocks rather than in the keypressed block itself- otherwise Scratch will think you're looking for a block (internally) named “a” rather than a key named “a”
Well it appears as if my method of editing the JSON doesn't work properly as even not changing the JSON at all and just passing it through the editor causes it to fail to load. Kinda stuck at this point lol
Well, how are you editing it/what software are you using?

Because it should work in an ordinary text editor.
MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

BigNate469 wrote:

Well, how are you editing it/what software are you using?

Because it should work in an ordinary text editor.
Well because I'm not on my main actual computer and instead on a school chromebook I have limited resources. I don't use a text editor app. Instead I have to load it into a JSON editor just to format it to be more readable (the JSON editor was the thing not saving properly), copy it, paste it into google docs, save the doc as a txt file, and convert the txt file to a JSON file. Rename everything back to normal. All of these different things are probably why it doesn't work properly. Also I have to load it into a JSON editor as you can't directly open JSON files w/ google docs.
BigNate469
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

MineTurte wrote:

BigNate469 wrote:

Well, how are you editing it/what software are you using?

Because it should work in an ordinary text editor.
Well because I'm not on my main actual computer and instead on a school chromebook I have limited resources. I don't use a text editor app. Instead I have to load it into a JSON editor just to format it to be more readable (the JSON editor was the thing not saving properly), copy it, paste it into google docs, save the doc as a txt file, and convert the txt file to a JSON file. Rename everything back to normal. All of these different things are probably why it doesn't work properly. Also I have to load it into a JSON editor as you can't directly open JSON files w/ google docs.
Well, if you want a really quick solution, you could try https://vscode.dev/ (open the unzipped folder of your project in it and it should save changes directly)

You will, however, have to indent the JSON manually.

Last edited by BigNate469 (Oct. 1, 2024 19:48:28)

ninjaMAR
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

BigNate469 wrote:

(#10)

MineTurte wrote:

BigNate469 wrote:

Well, how are you editing it/what software are you using?

Because it should work in an ordinary text editor.
Well because I'm not on my main actual computer and instead on a school chromebook I have limited resources. I don't use a text editor app. Instead I have to load it into a JSON editor just to format it to be more readable (the JSON editor was the thing not saving properly), copy it, paste it into google docs, save the doc as a txt file, and convert the txt file to a JSON file. Rename everything back to normal. All of these different things are probably why it doesn't work properly. Also I have to load it into a JSON editor as you can't directly open JSON files w/ google docs.
Well, if you want a really quick solution, you could try https://vscode.dev/ (open the unzipped folder of your project in it and it should save changes directly)

You will, however, have to indent the JSON manually.
You can format the document in VSCode. Open the command pallette, using CTRL + SHIFT + P (CMD + SHIFT + P on MacOS). Then type “Format document” and press enter.
MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

BigNate469 wrote:

MineTurte wrote:

BigNate469 wrote:

Well, how are you editing it/what software are you using?

Because it should work in an ordinary text editor.
Well because I'm not on my main actual computer and instead on a school chromebook I have limited resources. I don't use a text editor app. Instead I have to load it into a JSON editor just to format it to be more readable (the JSON editor was the thing not saving properly), copy it, paste it into google docs, save the doc as a txt file, and convert the txt file to a JSON file. Rename everything back to normal. All of these different things are probably why it doesn't work properly. Also I have to load it into a JSON editor as you can't directly open JSON files w/ google docs.
Well, if you want a really quick solution, you could try https://vscode.dev/ (open the unzipped folder of your project in it and it should save changes directly)

You will, however, have to indent the JSON manually.
Ooh I never knew VS code was able to be used on browser too. Thanks! Actually on my schools computer lab computer I can use VS code as I literally use it for school so thanks! I'll try it out
MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

Okay new problem… how would I turn the newly zipped file back to sb3? Normally I can do it but not atm…
BigNate469
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

MineTurte wrote:

Okay new problem… how would I turn the newly zipped file back to sb3? Normally I can do it but not atm…
(Assuming you're still on a Chromebook), right-click the folder in your files, click Zip Selection, and change the file extension to .sb3.

Additionally, Scratch can load from a .zip file (and has no problem with it, assuming it's essentally a renamed .sb3), if you set the file picker (note: this is not possible on all OSes) to allow “all files” rather than “custom files” or something similar.

Last edited by BigNate469 (Oct. 2, 2024 15:56:06)

MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

BigNate469 wrote:

MineTurte wrote:

Okay new problem… how would I turn the newly zipped file back to sb3? Normally I can do it but not atm…
(Assuming you're still on a Chromebook), right-click the folder in your files, click Zip Selection, and change the file extension to .sb3.

Additionally, Scratch can load from a .zip file (and has no problem with it, assuming it's essentally a renamed .sb3), if you set the file picker (note: this is not possible on all OSes) to allow “all files” rather than “custom files” or something similar.
Kk. I'll try the new method out!
MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

OK I got it to work and have been messing around with it but I think I just found something actually revolutionary… I'm not sure how I did it exactly but it's so cursed. I basically made a variable pause button. It pauses all actions on the variable until unpaused. This includes changing its visuals or values. Project here: https://scratch.mit.edu/projects/1076381233/
Anyone understand why this happens perhaps? Basically it's a ghost block but the parent custom block is a real block

UPDATE: It doesn't just freeze variables. It freezes the entire project. I tried with forever going to random locations and when the pause button is pressed, it stops. But it's weird as in it doesn't work the same as say the turbowarp pause button because even stuff in the editor gets frozen.

Last edited by MineTurte (Oct. 3, 2024 17:48:43)

Maximouse
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

MineTurte wrote:

OK I got it to work and have been messing around with it but I think I just found something actually revolutionary… I'm not sure how I did it exactly but it's so cursed. I basically made a variable pause button. It pauses all actions on the variable until unpaused. This includes changing its visuals or values. Project here: https://scratch.mit.edu/projects/1076381233/
Anyone understand why this happens perhaps? Basically it's a ghost block but the parent custom block is a real block

UPDATE: It doesn't just freeze variables. It freezes the entire project. I tried with forever going to random locations and when the pause button is pressed, it stops. But it's weird as in it doesn't work the same as say the turbowarp pause button because even stuff in the editor gets frozen.
Trying to run that block causes an error, so Scratch tries to run it again. If the same error occurs every time, it will get stuck in an infinite loop which prevents anything else from running.

Clicking the block for the second time stops it, which allows other scripts to continue.

Last edited by Maximouse (Oct. 4, 2024 10:38:21)

MalloryEverton
Scratcher
3 posts

How to properly change blocks by editing project JSON?

Do cloud variables actually work?
BigNate469
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

MalloryEverton wrote:

Do cloud variables actually work?

Unrelated to this topic, but they should work. The servers handling it have not been reliable lately, so there are cases where it simply doesn't.
MineTurte
Scratcher
1000+ posts

How to properly change blocks by editing project JSON?

closing topic when possible btw. Thx to everyone who helped!

Powered by DjangoBB