# I need help developing an extension

**URL:** <https://forum.makecode.com/t/i-need-help-developing-an-extension/6248>\
**Category:** Help\
**Created:** [February 18, 2021, 4:31pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248 "2021-02-18T16:31:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [February 18, 2021, 4:31pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/1 "2021-02-18T16:31:09Z")

</div>

So I was snooping around in the editor to see if I could find an avg function, but I can’t seem to find it, neither in JavaScript nor Blocks. So after that, I decided to make it into an extension, but can anyone who has made extensions help me? This is what I have so far…

> ```
> namespace Math {
> //% block="avg $value"
> export function avg(value: Array) {
> let temporaryValue = 0
> for (let index = 0; index < value.length; index++){
> temporaryValue += index
> }
> return (temporaryValue / value.length)
> }
> 
> ```

Is there a better way to do this? I’ve hit this error with the playground editor:

> Generic type ‘Array’ requires 1 or more argument(s)

Thanks

---

<div class="post-metadata">

**Author:** ![shakao](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/shakao/32/113_2.png) [@shakao](https://forum.makecode.com/u/shakao)\
**Post date:** [February 18, 2021, 4:36pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/2 "2021-02-18T16:36:38Z")

</div>

Great extension idea! The error you’re running into is that `value: Array` should be `value: number[]`. Arrays are represented by square brackets, and the “type” of the array is written before the brackets, so as another example, an array of sprites would be `value: Sprite[]`.

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [February 18, 2021, 6:12pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/3 "2021-02-18T18:12:50Z")

</div>

Another Questions, how do I make subcategories? Such as the life cycle and effect found in the sprites tab. Also here is the extension so far:

> **[agent14bricks/agent-14-essential-extensions](https://github.com/agent14bricks/agent-14-essential-extensions)**
>
> Will add various miscellaneous blocks, such as average, array of all sprites, and so much more!

And how can I make the input be a sprite kind?

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [February 18, 2021, 6:40pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/4 "2021-02-18T18:40:39Z")

</div>

You can define those with group attributes [https://makecode.com/defining-blocks#category-groups](https://makecode.com/defining-blocks#category-groups)

here’s a quick example from one of mine; setting the groups here: [https://github.com/jwunderl/pxt-status-bar/blob/efcd376357ae7215e65616a11283e03bceaa7fa2/status-bar.ts#L329](https://github.com/jwunderl/pxt-status-bar/blob/efcd376357ae7215e65616a11283e03bceaa7fa2/status-bar.ts#L329) and setting which group a block belongs to here [https://github.com/jwunderl/pxt-status-bar/blob/efcd376357ae7215e65616a11283e03bceaa7fa2/status-bar.ts#L871](https://github.com/jwunderl/pxt-status-bar/blob/efcd376357ae7215e65616a11283e03bceaa7fa2/status-bar.ts#L871)

For `spritekind` it’d be something like this:

```auto
//% blockId=allOfKind block="array of sprites of kind $kind"
//% kind.shadow="spritekind"
export function allOfKind(kind: number): Sprite[] {
    ...

```

(spritekind is the blockid of the block that makes the dropdown of spritekinds, and shadow says 'make tthe thing here start as ‘spritekind’ / have that stay around even if they drag something else on top of it)

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [February 18, 2021, 7:08pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/5 "2021-02-18T19:08:16Z")

</div>

So now I am trying to make it output a true/false statement,

> //% blockId=allOfKind block=“does sprite kind $kind exists”  
> //% kind.shadow=“spritekind”  
> export function allOfKind(kind: number): Sprite {  
> let temporaryVar = 0  
> for(let value of Extras.arrayOfAllSprites()){  
> temporaryVar += 1  
> }  
> if(temporaryVar \> 0){  
> return True  
> }  
> else{  
> return False  
> }  
> }

It gives me:

> Cannot find name ‘True’

The same thing for false  
can you help me @jwunderl

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [February 18, 2021, 7:10pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/6 "2021-02-18T19:10:43Z")

</div>

In javascript true / false is all lowercase

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [February 18, 2021, 7:25pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/7 "2021-02-18T19:25:30Z")

</div>

Now it says True is not assignable to type ‘Sprite[]’

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [February 19, 2021, 4:12pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/8 "2021-02-19T16:12:24Z")

</div>

Do you know how I can fix this?

> //% blockId=allOfKind block=“does sprite kind $kind exists”  
> //% kind.shadow=“spritekind”  
> //% group=“SpriteKind”  
> export function allOfKind(kind: number): Sprite {  
> let temporaryVar = 0  
> for(let value of Extras.arrayOfAllSprites()){  
> temporaryVar += 1  
> }  
> if(temporaryVar \> 0){  
> return true  
> }else{  
> return false  
> }  
> }

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [February 19, 2021, 5:01pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/9 "2021-02-19T17:01:35Z")

</div>

The return type of the function is wrong - its saying its returning an array of sprites (`: Sprite[]`) where you’re trying to return a `boolean` value. Just swap `Sprite[]` with `boolean`.

Also, you’ll need to change the blockId (and probably the function name too to give it something meaningful) - the example I gave was mostly copied from code in the editor by default, leaving it as `allOfKind` will conflict with the default sprite block.

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [February 19, 2021, 7:34pm UTC](https://forum.makecode.com/t/i-need-help-developing-an-extension/6248/10 "2021-02-19T19:34:33Z")

</div>

Another Question, Why does this happen:

> **[Microsoft MakeCode Arcade](https://arcade.makecode.com/#testproject:121ea895-cdcf-48eb-b047-18d1acde20c4)**
>
> Develop your programming skills by quickly creating and modding retro arcade games with Blocks and JavaScript in the MakeCode editor

Check the extension
