# Utility Extension 1.0

**URL:** <https://forum.makecode.com/t/utility-extension-1-0/19142>\
**Category:** Show & Tell\
**Tags:** extension\
**Created:** [April 12, 2023, 4:00pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142 "2023-04-12T16:00:14Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 12, 2023, 4:00pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/1 "2023-04-12T16:00:15Z")

</div>

I’ve made an extension with useful utility blocks, there are blocks for things like JSON and text. To use it open the extensions menu, put in [https://github.com/usertheusernamer/pxt-utilities](https://github.com/usertheusernamer/pxt-utilities) inside the top textbox, and click on the extension.

 ![extension](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/5/5c26d96846b2a1407f64827d64b6519bc16be960.png)

Here is the currently available blocks in 1.0:

 ![utilities](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4d772198bcdff743a7f0d0d5b5430662ed0a450c.png)

I’d like to add two new blocks that act like try and try-catch statements (Handles errors and prevents crashing), but it seems like try-catch statements aren’t supported. If you have any more block ideas, tell me and I’ll add them.

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [April 12, 2023, 7:53pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/2 "2023-04-12T19:53:32Z")

</div>

I have a utility idea! Long strings of if/else can get confusing, perhaps implementing something like the [The ‘case’ function in swift](https://www.hackingwithswift.com/read/0/10/switch-case) that can have one output for each possible input without long lines of if/else.

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 12, 2023, 10:54pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/3 "2023-04-12T22:54:38Z")

</div>

Sounds like a great idea but after thinking a while, I don’t think it’s possible to implement that as an extension and wouldn’t it look like the same as if-else blocks? Maybe you are placing separate if-else blocks into other if-else blocks? You could just click the plus icon on an if statement and that expands into an if-else statement, another click and it turns into a if-elseif-else statement. It’s not really necessary to implement a switch-case block (also seems impossible due to extension limitations, not the code but how the block behaves like how to expand it) and a large if statement (No nests, just a single giant if-elseif-elseif-elseif-elseif-else block.) would basically be the same if I ever implemented a switch-case block. Sorry if my English is not that easy to read and understand but I like the idea.

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [April 12, 2023, 11:02pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/4 "2023-04-12T23:02:43Z")

</div>

Could you implement some missing array methods? Like includes and concatenation? It would be really useful! Anyway, nice idea for an extension!

> [@EpicKitty](#):
>
> try-catch statements aren’t supported

Are you sure? This [source](https://makecode.com/language) states they’re supported.

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [April 13, 2023, 2:37am UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/5 "2023-04-13T02:37:09Z")

</div>

True, it would work _almost_ exactly like a long if/elseif statement, but cases are different. One input is put up top and each case compares to that. So, instead of having something like ‘If x=0 then this, if x=1 then this, if x=2 then this’ you could have ‘case x: equals 0 then this, equals 1 then this, equals 2 then this’! I’m guessing it probably still can’t be done but thanks for explaining and considering!! : D

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 13, 2023, 4:31pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/6 "2023-04-13T16:31:15Z")

</div>

> [@Sarge](#):
>
> Could you implement some missing array methods? Like includes and concatenation? It would be really useful! Anyway, nice idea for an extension!

I’ll add those, nice idea!

> [@Sarge](#):
>
> Are you sure? This [source](https://makecode.com/language) states they’re supported.

Weird, I don’t think they work in extensions though. Like running the user’s code in a try-catch statement still produces an error and crashes.

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 13, 2023, 4:31pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/7 "2023-04-13T16:31:35Z")

</div>

Do you mean something like this?

 ![scratchblocks](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/d/dcdc2178da98d838a369bf57fe0a20c504c83221.png)

Yes, I used scratchblocks, the quickest way I can create an example on mobile.

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [April 13, 2023, 4:56pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/8 "2023-04-13T16:56:53Z")

</div>

Could you provide an example or sample code that reproduces this error?

Anyways, I just remembered I already made a concatenation method in one of my extensions before!

> **[GitHub - S0m3randomguy/array-methods: A MakeCode project](https://github.com/S0m3randomguy/array-methods)**
>
> A MakeCode project. Contribute to S0m3randomguy/array-methods development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 13, 2023, 5:15pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/9 "2023-04-13T17:15:45Z")

</div>

Here’s both the code for try and try\_catch blocks:

```auto
namespace utilities {
    //% block="try"
    //% blockId="ue_try"
    //% group='Error Handling'
    //% handlerStatement=true
    //% weight=7
    export function ue_try(run: () => void): void {
        try {
            run();
        } catch {}
    }

    //% block="try catch"
    //% blockId="ue_try_catch"
    //% group='Error Handling'
    //% handlerStatement=true
    //% weight=6
    export function ue_tryCatch(run: () => void, c: (errorName: string) => void): void {
        try {
            run();
        } catch (error) {
            c(error.name);
        }
    }
}

```

These are inside the utilities namespace in the extension, I’ve put a block in that causes an error and that did not work even when my code was like this:

 ![error](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/0/0f1aa4575c2c70827daa21ae3e285a5e7e2c2004.png)

> [@Sarge](#):
>
> Anyways, I just remembered I already made a concatenation method in one of my extensions before!

Nice, I might add all these blocks for arrays into my extension:

- include - \<array [array] includes [any]?\>
- join - (join [array] with [text])
- concat - (concat [array] and [array])
- indexOf - (index of [any] in [array])
- unshift - (unshift [any] into [array])
- slice - (slice [array] with [number] items)
- sort - (sort [array] by [ascending, descending v])

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 13, 2023, 5:19pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/10 "2023-04-13T17:19:59Z")

</div>

Forgot to mention/reply @Sarge (So that he sees the notification)

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [April 13, 2023, 5:57pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/11 "2023-04-13T17:57:59Z")

</div>

I’m making a List extension that will add a custom datatype: Lists, similar to those in Python.  
The methods implemented at the moment are the following:

## Item operations

- **get** - get item at index
- **set** - set item at index
- **delete** - delete item at index
- **push** - push item to the end of list
- **pop** - remove and return item at index
- **insert** - insert item at index
- **find** - return index of item if found
- **remove** - remove the first occurence of an item
- **swap** - swap items at two indexes
- **replace** - replace all occurences of item with value
- **random** - return random item from list
- **count** - count item repetitions in list

## List operations

- **extend** - append other list to the end of list
- **flatten** - unpack all lists within the list recurively (depth=0 is infinite depth)
- **slice** - return list items from start to end
- **isList** - static method; return true if item is of list type
- **inRange** - return if number is within length of the list
- **contains** - return true if item is in list
- **compress** - remove all undefined values
- **patch** - fill all undefined values with static value
- **fill** - fill with static value from start to end
- **zip** - return pairs of elements from two lists (until smaller length is exceeded)
- **reverse** - reverse the list
- **forEach** - iterate over the list items with value and index
- **clear** - remove all items from list
- **copy** - return new instance with matching items
- **isEmpty** - return true if list contains no elements
- **all** - return true if all items in list are true
- **any** - return true if any item in list is true
- **union** - return items that appear in both lists
- **purge** - remove all duplicates from list

Some of these are inspired by Python methods, some by JS methods and some are my own. These are not final, I might change or update them in the future. Yeahhh, I kind of spoiled my next project after the mini game jam, if anyone’s reading this.  
I’m still planning to implement `splice` and some other missing methods.

At the moment, i’m working on porting all of the methods to blocks, so I can release it as an extension at last.

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [April 13, 2023, 6:15pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/12 "2023-04-13T18:15:28Z")

</div>

![Screenshot 2023-04-13 140759](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/76f30115e974db3a17e7763a51d7761a85b43378.png)  
That looks so cool!! Its a little more like this:

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 13, 2023, 6:20pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/13 "2023-04-13T18:20:49Z")

</div>

That’s a lot! Pretty impressive, I’m sure a lot of people will use that. Are you gonna define all these blocks into a single main.ts file or are you gonna make them apart like maybe every category has it’s own file?

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [April 13, 2023, 6:28pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/14 "2023-04-13T18:28:57Z")

</div>

The datatype (as a class) and its metods are in `lists.ts`, and the block interface functions are in `main.ts`

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 14, 2023, 4:45pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/15 "2023-04-14T16:45:33Z")

</div>

Ah, I might have forgotten how a switch statement looked like. I might be able to add that to my extensions.

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [April 14, 2023, 4:54pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/16 "2023-04-14T16:54:31Z")

</div>

thats so cool! thanks for helping!

---

<div class="post-metadata">

**Author:** ![BotWarrior](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/botwarrior/32/25328_2.png) [@BotWarrior](https://forum.makecode.com/u/BotWarrior)\
**Post date:** [July 23, 2025, 12:51pm UTC](https://forum.makecode.com/t/utility-extension-1-0/19142/17 "2025-07-23T12:51:21Z")

</div>

The json blocks to object in this extension, what would be a cool example of those? I feel like they could be very useful and I have wished for blocks in the past like these… If not, sorry for reviving this topic. Maybe other people haven’t seen this extension and it could help them.
