Making an extension for every JavaScript exclusive feature I can think of!

WoofWoofCodes/pxt-javascript-extras

Basically what I want to make is an extension for all those single-line functions that are only accessible in javaScript. This is going to be a running project that I’ll update over time, as I discover javaScript exclusive features. If you find a function in javaScript you would like added, just post it here or create a pull request on the GitHub page. If you do it correctly, with a small description attached to your blocks implementation and everything, making a pull request will be much faster then posting here.

So far I have:

  • some image manipulation blocks and the blocks from that image scale extension I made
  • blocks for changing the font/background/border colors of Info hud elements
  • and one for changing the “lives” image
  • blocks for getting/setting the screen brightness
  • system menu stuff like opening it and closing it, trying to add blocks for making menu items right now
  • a block to check if a sprite has a certain Flag enabled (think “bounce on walls” and “invisible” flags)
  • that little color picker insert that I stole from @UnsignedArduino’s ColorBlock extension

Things I am not planning to add yet, but may be added in the future:

  • Everything Buffers
  • Music stuff
  • Stuff that well known extensions already add, like the Settings extension and the Colors extension

Things that I cannot physically add in an extension but know people will ask for

  • Screen size changing
  • More than 16 colors

If you ask for something, I will like (:heart_suit:) your post if I think I can add your idea!

Yeah sure I’ll add those @AlexK

11 Likes

For completeness, how about these two:

image.print()
image.printCenter()

They’re not really necessary, since we have the Text Sprite and the Fancy Text extensions, but they’re simple enough to implement.

5 Likes

I’ve added the print blocks, as well as some basic Buffer blocks! I also added array.slice and array.copy because I needed them for a blocks project I was working on.

3 Likes

sarge’s betterarrays extension has a ton of array stuff like copying you should check it out!

3 Likes

May I ask why you can’t add screen size change?

It’s seems rather simple whenever I copy/paste it in…

(I am a blocks coder, I don’t understand this stuff.)

3 Likes

i NEED an invisible block for my game (life sprite too ig but carnival exists) gl @WoofWoof!

1 Like

Blocks aren’t bits of code you are adding into your game, they are functions being called by blocks, and the inputs to the function is what you put the block. When you use the JavaScript code to change the screen size, you are overriding those constant variables, which you can’t do inside a function because you are basically re-defining a constant, so we can’t turn them into blocks.

Ummm @Reflectfr can you explain what you mean by that??

4 Likes

a block that makes a specific sprite invisible, like a camera that follows the sprite with a slight delay

1 Like

That already exists!


You could also just make a sprite with an empty image. If you turn on that “ghost” option, or “ghost through walls” then the sprite will be able to go through walls just like the camera.

4 Likes

W H A T I never knew that

3 Likes

Added blocks for using the music.playInstructions and music.addNote functions! Also a small block for finding the volume set by the user in the system menu, which you need because the playInstructions function bypasses the system volume.
I also added the setPalette block. 16 colors, one byte per color channel (rgb) so the input buffer should be 48 bytes long.

3 Likes

As promised, here is your sounds example project:

press A to hear the sound!

Maximum volume is 1024. Idk if there is a maximum hz, but there is a point at which us humans can no longer physically hear the sound, so that’s probably the limit.

Each sound instruction takes up 12 bytes of the buffer.

These are all the possible instruments:
1 - triangle
2 - sawtooth
3 - sine
4 - pseudorandom square wave noise (tunable)
5 - white noise (ignores frequency)
11 - square 10%
12 - square 20%

15 - square 50%
16 - filtered square wave, cycle length 16
17 - filtered square wave, cycle length 32
18 - filtered square wave, cycle length 64

4 Likes

I OBJECT TO THIS

The purpose of JavaScript exclusive features is to get people to Learn and Use JavaScript and not use blocks forever

1 Like

The real reason to use JavaScript is that makecode won’t randomly delete stuff.
If people wanted to learn JavaScript, they would do it. This extension shows people that there are way more features in JavaScript than in blocks, more than I could possibly find and add by myself. If I could add things like namespaces and classes in blocks, I would, because I think everyone should be able to use such features without having to use written code.

Objection overruled.

4 Likes

Thanks for sharing this Woof. These sounds are just amazing.

1 Like