Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Leopard: Edit Scratch projects as JavaScript code
- 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.![](//cdn.scratch.mit.edu/scratchr2/static/__2c91a3655952ea89512f9f962f15b1af__/djangobb_forum/img/smilies/smile.png)
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.
![](http://cdn.scratch.mit.edu/scratchr2/static/__2c91a3655952ea89512f9f962f15b1af__/djangobb_forum/img/smilies/smile.png)
- 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
![](http://cdn.scratch.mit.edu/scratchr2/static/__2c91a3655952ea89512f9f962f15b1af__/djangobb_forum/img/smilies/sad.png)
but what I can do is to probably make this into an npm module (if you haven’t already published one yet)
I’m @jvn11
CONSIDER FOLLOWING ME ON SCRATCH AND YOUTUBE!
forever
Be [awesome] and [kind]
Always.
Yes
end
—————————————————————
- 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![](//cdn.scratch.mit.edu/scratchr2/static/__9209616f20ac7fc52efa806cd216a370__/djangobb_forum/img/smilies/smile.png)
https://codesandbox.io/s/ecstatic-faraday-ewlvco
![](http://cdn.scratch.mit.edu/scratchr2/static/__9209616f20ac7fc52efa806cd216a370__/djangobb_forum/img/smilies/smile.png)
I’m @jvn11
CONSIDER FOLLOWING ME ON SCRATCH AND YOUTUBE!
forever
Be [awesome] and [kind]
Always.
Yes
end
—————————————————————
- 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! ![](//cdn.scratch.mit.edu/scratchr2/static/__2c91a3655952ea89512f9f962f15b1af__/djangobb_forum/img/smilies/big_smile.png)
![](http://cdn.scratch.mit.edu/scratchr2/static/__2c91a3655952ea89512f9f962f15b1af__/djangobb_forum/img/smilies/big_smile.png)
- 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
- Aneri9714
-
100+ posts
Leopard: Edit Scratch projects as JavaScript code
It's amazing! I can now learn js (little bit?)
Abandoned forumer
- -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)
This is my signature, it appears on all my posts.
I just can't refrain
Bitterness, so quaint
One more shot, never again
All the excuses, always the same
All the times I tried
I just couldn't get over you
I just cannot hide
The satisfaction you can brew
One more sip embraced
My worries disappear for a while
Then it all comes, comes kicking in
They told me it's alright
They say that I'll get through
But however hard that I try
I just can get over you
When it all comes kicking in, again
Now I'm shaken
Stirred, awaken
It's taken this pain
To realize the truth
You have been through
All the things I've been through
You can be my muse
I'll write these songs for you
- 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!
![](http://cdn.scratch.mit.edu/scratchr2/static/__4f30ecd4943fbeccd89d004edc4792db__/djangobb_forum/img/smilies/smile.png)
- 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
-
85 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)
Please dont ask me where i got my emojis. I found this random website that has cubeupload links to bbcode-styled emojis. https://gh.vercte.net/forumoji/
i wouldn't mind if you used shift+down to scroll through my signature.
when I create a (forum post v) :: events hatPROTEST AGAINST SCRATCH IMAGES AI.
wait (60) seconds :: control // 60-second demon was here
create another (forum post v) :: sensing
—
Might register for cubeupload soon so I can at least upload images.
I can only speak english and some french. If I'm not speaking English, I'm using Google Translate.
all hail our glorious leader
Will i work on cookie clicker 3? yes i will answer myself.
Why do people keep spamming tags just for fame? Hint: Scratch only lets you have up to 15 tags per project
I might be able to write an entire novel in my siggie but then the important stuff will be hard to find. + if I post, and someone sees a topic, scratch bandwith stonks go down.
Last edited by kaj (Tomorrow 00:00:00)
- 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)
when flag clicked
forever
Imagine :: motion stack
Program :: sensing stack
Share :: operators stack
end