Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Leopard: Edit Scratch projects as JavaScript code
- jvn11
-
70 posts
Leopard: Edit Scratch projects as JavaScript code
hey. I was thinking if I can help with leopard? I know JavaScript, Python, html, css, and scratch (obv).
- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
Right now I really want help discovering cool ideas for how to use Leopard. Converting Scratch projects to JavaScript is obviously cool, but the most exciting part is if you can start to add JavaScript code to your project that enables new features that aren't possible in Scratch. hey. I was thinking if I can help with leopard? I know JavaScript, Python, html, css, and scratch (obv).
For example, using Leopard you could enhance your project by:
- Making a sprite that opens a website in a new tab when clicked
- Using JavaScript alert(), prompt(), and confirm() boxes
- Changing other things on the webpage, like the page's background color, or adding new HTML elements
These are my ideas, but I feel like there is a lot more to do that I just haven't thought of yet. It would be fun to build a library of cool project ideas, and I need help doing so. Maybe you could contribute some ideas and example projects?
- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
Here's an example of what I'm talking about, jvn11: https://codesandbox.io/s/stoic-golick-i6st4h?file=/Sprite1/Sprite1.js
When you click the Scratch cat, it opens the Scratch website in a new tab. Not possible in a regular Scratch project!
Everyone reading this, please create more example projects like this one! I want to see all your ideas.
When you click the Scratch cat, it opens the Scratch website in a new tab. Not possible in a regular Scratch project!
Everyone reading this, please create more example projects like this one! I want to see all your ideas.

- jvn11
-
70 posts
Leopard: Edit Scratch projects as JavaScript code
https://codesandbox.io/s/stoic-golick-i6st4h?file=/Sprite1/Sprite1.jsHere's an example of what I'm talking about, jvn11:
When you click the Scratch cat, it opens the Scratch website in a new tab. Not possible in a regular Scratch project!
Everyone reading this, please create more example projects like this one! I want to see all your ideas.
so something like a scratch extension? the problem is that I don’t know how to actually make one

but what I can do is to probably make this into an npm module (if you haven’t already published one yet)
- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
so something like a scratch extension? the problem is that I don’t know how to actually make one
but what I can do is to probably make this into an npm module (if you haven’t already published one yet)
No need to write an extension. After converting your project to Leopard code, you can edit the JavaScript to do whatever you want! Even things that are impossible in Scratch.
For example, to create the project I linked above, I started by creating a Scratch project that did nothing when you clicked on the Scratch cat. Then I converted my project to Leopard. The converted project still did nothing when clicking the cat. But now, because I was working in JavaScript land, I could add that additional functionality myself, without relying on the automatic converter.
Try editing my JavaScript code in the example project. Can you change it to open a different website?
- jvn11
-
70 posts
Leopard: Edit Scratch projects as JavaScript code
Hey @PullJosh. I made this program that first asks you for your username, then it outputs your username + date & time.
https://codesandbox.io/s/ecstatic-faraday-ewlvco
https://codesandbox.io/s/ecstatic-faraday-ewlvco

- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
Leopard updates!
Thanks to towerofnix and adroitwhiz, Leopard has some new updates to share!
Leopard now supports the following blocks:
Additionally, pen and “when this sprite clicked” were both made more compatible with Scratch. And now that “touching edge” is available, support for “if on edge, bounce” is closer than ever.
Thanks to towerofnix and adroitwhiz, Leopard has some new updates to share!
Leopard now supports the following blocks:
when [timer v] > (10)
when [loudness v] > (10)
(loudness)
<touching [edge v] ?>
Additionally, pen and “when this sprite clicked” were both made more compatible with Scratch. And now that “touching edge” is available, support for “if on edge, bounce” is closer than ever.
- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
The Leopard website now features a live-updating list of recently converted projects. Hopefully now it's easier to find and connect with other Scratchers who are using Leopard. Give it a try! 

- NoodlesAdun
-
2 posts
Leopard: Edit Scratch projects as JavaScript code
Hello, I was trying to convert a project using leopard but it keeps giving the error message “Cannot read properties of undefined (reading ‘0’)”.
I'm not using any unsupported blocks or extensions, so does anyone know where I've gone wrong?
the project url is: https://scratch.mit.edu/projects/714577157
I'm not using any unsupported blocks or extensions, so does anyone know where I've gone wrong?
the project url is: https://scratch.mit.edu/projects/714577157
- Taro--Sasaki
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
Does it work on mob.?
- Aneri9714
-
100+ posts
Leopard: Edit Scratch projects as JavaScript code
It's amazing! I can now learn js (little bit?)
- -Cold-lord-X-
-
100+ posts
Leopard: Edit Scratch projects as JavaScript code
finally. Trying it out now!
Last edited by -Cold-lord-X- (Aug. 2, 2022 16:27:09)
- PullJosh_Test
-
7 posts
Leopard: Edit Scratch projects as JavaScript code
Great question! I did some digging and found that there are two separate issues that both cause this error. Hello, I was trying to convert a project using leopard but it keeps giving the error message “Cannot read properties of undefined (reading ‘0’)”.
I'm not using any unsupported blocks or extensions, so does anyone know where I've gone wrong?
the project url is: https://scratch.mit.edu/projects/714577157
Problem 1: The first is that you have a variable and a list with matching names. This is something Leopard should know how to handle, but it currently doesn't. That's our fault, and it should work, but in the meantime you can always rename your lists to make them not match the variables, and that will solve this issue.
Problem 2: The second problem is a little weirder. It seems like in the “editor” sprite, the variables tileGridX, tileGridY, tileIndex, and tile are each defined twice. This isn't visible at all in the Scratch editor, but you can see it when you open up the JSON code under the hood. I have no idea how this happened–I don't think it's supposed to be possible.
Here's an excerpt from your project's underlying JSON code so that you can see what I mean:
{ "isStage": false, "name": "editor", "variables": { "W_1Y0o*^b}}4=Y+cjm2g": ["tileGridX", 8], "Vjh+7?#YS@#6q-B-/@%T": ["tileGridY", 8], "rYY+5aWXjq/pBK8^Gt}w": ["tileIndex", 169], "}h`kH)KZh-HrN9g!t-Ny": ["tile", "2"], "0?:.QV{uMFG;@i]L!h1n": ["brush", "0"], "7De62Pt(pTCegwvxFOvY": ["brush1", 1], "dx(wx8v7)/y!iWIhW1CH": ["brush2", 1], "]LIbaT9ymB}x1antS-|d": ["brush3", 10], "NkJRP6FQdQ3YU#Aei/=r": ["tileGridX", 0], "(_.u_-_ZB09^R`v2~*.K": ["tileGridY", 0], "aGQ*p%}CAQLiF45ZB6n~": ["tileIndex", 0], "1{y0BG5T,ZjEF4{Kgl#t": ["tile", 0], "@pi?X+CgpM=SZ[B4~`}q": ["brush4", 3], "^VrYP)X.I;MP}r6D2FYe": ["brush5", 0], "_qt3@[rs*m=(`ZfC-T#|": ["brush6", 9], "OU,k{M/7-Q4|=+kuC3SY": ["brush#", "2"], "t1cz`Jspd|;lIPxKu(vK": ["brush7", 0] }, // etc... }
Under the hood, variables are given ids that are basically just strings of garbage (in green above). What's weird is that there are two variables called tileGridX, two variables called tileGridY, and so on. (But there is just one of each “brush” variable as expected.) This obviously makes Leopard very confused, and causes the error. Fixing this one seems harder because I don't know how it even happened in the first place.
- NoodlesAdun
-
2 posts
Leopard: Edit Scratch projects as JavaScript code
Great question! I did some digging and found that there are two separate issues that both cause this error. Hello, I was trying to convert a project using leopard but it keeps giving the error message “Cannot read properties of undefined (reading ‘0’)”.
I'm not using any unsupported blocks or extensions, so does anyone know where I've gone wrong?
the project url is: https://scratch.mit.edu/projects/714577157
Problem 1: The first is that you have a variable and a list with matching names. This is something Leopard should know how to handle, but it currently doesn't. That's our fault, and it should work, but in the meantime you can always rename your lists to make them not match the variables, and that will solve this issue.
Problem 2: The second problem is a little weirder. It seems like in the “editor” sprite, the variables tileGridX, tileGridY, tileIndex, and tile are each defined twice. This isn't visible at all in the Scratch editor, but you can see it when you open up the JSON code under the hood. I have no idea how this happened–I don't think it's supposed to be possible.
Here's an excerpt from your project's underlying JSON code so that you can see what I mean:{ "isStage": false, "name": "editor", "variables": { "W_1Y0o*^b}}4=Y+cjm2g": ["tileGridX", 8], "Vjh+7?#YS@#6q-B-/@%T": ["tileGridY", 8], "rYY+5aWXjq/pBK8^Gt}w": ["tileIndex", 169], "}h`kH)KZh-HrN9g!t-Ny": ["tile", "2"], "0?:.QV{uMFG;@i]L!h1n": ["brush", "0"], "7De62Pt(pTCegwvxFOvY": ["brush1", 1], "dx(wx8v7)/y!iWIhW1CH": ["brush2", 1], "]LIbaT9ymB}x1antS-|d": ["brush3", 10], "NkJRP6FQdQ3YU#Aei/=r": ["tileGridX", 0], "(_.u_-_ZB09^R`v2~*.K": ["tileGridY", 0], "aGQ*p%}CAQLiF45ZB6n~": ["tileIndex", 0], "1{y0BG5T,ZjEF4{Kgl#t": ["tile", 0], "@pi?X+CgpM=SZ[B4~`}q": ["brush4", 3], "^VrYP)X.I;MP}r6D2FYe": ["brush5", 0], "_qt3@[rs*m=(`ZfC-T#|": ["brush6", 9], "OU,k{M/7-Q4|=+kuC3SY": ["brush#", "2"], "t1cz`Jspd|;lIPxKu(vK": ["brush7", 0] }, // etc... }
Under the hood, variables are given ids that are basically just strings of garbage (in green above). What's weird is that there are two variables called tileGridX, two variables called tileGridY, and so on. (But there is just one of each “brush” variable as expected.) This obviously makes Leopard very confused, and causes the error. Fixing this one seems harder because I don't know how it even happened in the first place.
It's possible that when I was editing the project with turbowarp it somehow duplicated the variables, I'll try remaking the sprite and renaming the lists and hopefully it will work then. Thanks for the help!
- cdawgscratch
-
1 post
Leopard: Edit Scratch projects as JavaScript code
leapord is so cool but its very laggy on my device for some reason, do you think there might be something causing that?
- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
It's possible that when I was editing the project with turbowarp it somehow duplicated the variables, I'll try remaking the sprite and renaming the lists and hopefully it will work then. Thanks for the help!
Let me know how it goes!

- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
I'm not sure. What kind of device are you on? And is it always laggy or only for certain projects? leapord is so cool but its very laggy on my device for some reason, do you think there might be something causing that?
- A-MARIO-PLAYER
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
I'm not sure why nobody has posted this. My project keeps failing with:
Argument sandboxId for data.sandboxId is missing.
Last edited by A-MARIO-PLAYER (Aug. 6, 2022 14:45:13)
- PullJosh
-
1000+ posts
Leopard: Edit Scratch projects as JavaScript code
Which project is failing? I'm not sure why nobody has posted this. My project keeps failing with:Argument sandboxId for data.sandboxId is missing.
- BloodstoneAsh
-
7 posts
Leopard: Edit Scratch projects as JavaScript code
Following along with what a mario player said, I also have the same question. I had remixed griffpatch's Paper Minecraft project just for kicks to look at the code and stuff, but I am also wondering why I get an argument sandboxId for data.sandboxId is missing.
Last edited by BloodstoneAsh (Aug. 10, 2022 21:05:08)