# \[Extension\] - Declutter your variables!

**URL:** <https://forum.makecode.com/t/extension-declutter-your-variables/18813>\
**Category:** Show & Tell\
**Tags:** extension\
**Created:** [March 27, 2023, 11:17pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813 "2023-03-27T23:17:50Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [March 27, 2023, 11:17pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/1 "2023-03-27T23:17:50Z")

</div>

Hey everyone, I’m back from my hiatus and I’m planning to get serious now! In the following weeks/months you can expect:

- A list datatype extension (Python-like)
- A map/dictionary datatype extension (similar to [BlockObjects](https://github.com/microsoft/arcade-block-objects))
- A ‘BetterSettings’ extension, adding new datatypes to save using the [settings](https://forum.makecode.com/t/quick-tutorial-on-the-settings-namespace/1013) namespace
- Making my version of @PixelDoodle’s [CyberShift](https://forum.makecode.com/t/cybershift-v-4-5-new-art/17492)
- Helping with @AbstractDesigner’s [Speedun](https://forum.makecode.com/t/speedrun-dungeon/16337/27)
- More tutorials such as [this one](https://forum.makecode.com/t/360-aiming-showcase-tutorial/15614) I made a while back
- UI Element extension
- 

A jam of my own? 🤨

And much more!  
I’ll also try to participate in more jams, like @Unique’s [UAT2](https://forum.makecode.com/t/applicants-for-unique-a-thon-2/18209)

* * *

But anyways, that aside - it’s time to talk about the extension:

## But what is cluttering anyway?

* * *

I’d define cluttering in general as adding unecessary components to your code that make your workspace harder to use and reduce efficiency, but also make it harder to understand the code (especially for collaborators).

This is mostly prominent with block code, but it’s not uncommon for JS code too. A form of cluttering I often see is redundant variables taking up the namespace that are only used once for temporary sprites.

## How does this extension help, and how does it work?

* * *

To try and combat this problem, I thought of a simple sprite management stack. (Well, it’s not really a stack, but it sounds better so we’ll roll with that terminology)

Using the extension, you can load a sprite object to this _stack_ with a label, and the sprite can later be accessed and used as any other sprite stored in a variable (img. 1).

 ![(Image 1)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/9b8c3fecb0e0f48a38877208f46c364aa52e1757.png)

When you’re done using the sprite, you can offload it, which will remove it from the stack and destroy it (img. 2).

 ![(Image 2)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/b/bde7a8085a63289d4e00d23509f15dc94615b92d.png)

**WARNING (1/2): Destroying a sprite won’t remove it from the stack alone**  
**(2/2): Accesing non-existing items will throw a sprite stack extension**

## Available blocks

* * *

There are 4 available blocks at the moment:

**Load sprite**  
Loads the given sprite into the stack under the defined name

```auto
load <sprite> with name <name>

```

![Load sprite](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/5/56e5752183d857470dfac0d43f087c6132453271.png)

**Get sprite from stack**  
Returns sprite object by name from the stack. If a sprite with that name is not found, an error is thrown.

```auto
get sprite with name <name>

```

![Get sprite](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/ec3b5500c2b4b575a795406e33ffb828428bd56a.png)

**Offload sprite**  
Destroys and removes sprite from the stack by name. If a sprite with that name is not found, an error is thrown.

```auto
offload sprite with name <name>

```

![Offload sprite](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/92c82238b636f3ced2806ec51cf8649447426793.png)

**Check if sprite with a name exists**  
Returns true if a sprite with the given name exists in the stack.

```auto
stack contains sprite with name <name>

```

![Stack contains sprite](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/13b4d7c664d3b8e3c6fa8e83bfa0b6fef4f4e01b.png)

* * *

To conclude this, I’d like to say that I’ve been sitting on this idea for quite a while, so I’m glad to release it now since it only took me like 15 minutes to make this extension.  
If you have any questions or problems, feel free to ask here or submit an issue!

(Repo/extension link)

> **[GitHub - sargedev/declutter: Declutter your MakeCode blocks workspace](https://github.com/sargedev/declutter)**
>
> Declutter your MakeCode blocks workspace

---

<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 1, 2023, 5:24pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/2 "2023-04-01T17:24:37Z")

</div>

Thank you everone for the support, it means a lot! If you have any suggestions you can leave them here for future development although i’m moving on with other projects now so it won’t be in focus

---

<div class="post-metadata">

**Author:** ![AbstractDesigner](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/abstractdesigner/32/22531_2.png) [@AbstractDesigner](https://forum.makecode.com/u/AbstractDesigner)\
**Post date:** [April 1, 2023, 5:30pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/3 "2023-04-01T17:30:52Z")

</div>

I have no idea what that means but it sounds genius!

---

<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 3, 2023, 4:09pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/4 "2023-04-03T16:09:36Z")

</div>

Well, it’s just for cleaning up, honestly. Say you had a title screen sprite that only appeared at the start, creating a variable just for it clutters up your namespace. I’ve seen this with so many projects where there are many redundant variables. With this extension, you can just drop them in the stack and remove them when they’re not required anymore. That way, your variables remain clean for only the values you really need.

---

<div class="post-metadata">

**Author:** ![PixelDoodle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/pixeldoodle/32/24129_2.png) [@PixelDoodle](https://forum.makecode.com/u/PixelDoodle)\
**Post date:** [April 3, 2023, 4:10pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/5 "2023-04-03T16:10:14Z")

</div>

This is insane! I was going to add this to Pixel Smash but then I remembered that if it doesnt mean anything for the game, I was gonna have to go to Javascript, remove the extension, and Cry for several hours because I get the message: “Program to big to convert to blocks”

Still really cool though!

---

<div class="post-metadata">

**Author:** ![Unique](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unique/32/32724_2.png) [@Unique](https://forum.makecode.com/u/Unique)\
**Post date:** [April 3, 2023, 4:10pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/6 "2023-04-03T16:10:49Z")

</div>

@Sarge Love to see you back! Also like, this extension is the definition of ✨_optimization_ ✨. Great stuff!

(p.s. this extension is now one of my favs for the sole fact that i hate when my projects end up having like 4 million placeholder sprite variables, so “declutter” I shall do 😁!)

---

<div class="post-metadata">

**Author:** ![AbstractDesigner](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/abstractdesigner/32/22531_2.png) [@AbstractDesigner](https://forum.makecode.com/u/AbstractDesigner)\
**Post date:** [April 3, 2023, 4:11pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/7 "2023-04-03T16:11:02Z")

</div>

> [@Sarge](#):
>
> Helping with @AbstractDesigner’s [Speedun](https://forum.makecode.com/t/speedrun-dungeon/16337/27)

I can’t wait to have Speedun fixed! (｡･ω･｡)

---

<div class="post-metadata">

**Author:** ![ChimbroDaPro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chimbrodapro/32/15852_2.png) [@ChimbroDaPro](https://forum.makecode.com/u/ChimbroDaPro)\
**Post date:** [April 3, 2023, 4:21pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/8 "2023-04-03T16:21:06Z")

</div>

Wut dus that mean…

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [April 3, 2023, 4:31pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/9 "2023-04-03T16:31:40Z")

</div>

somehow i understand this. this would be helpful for my other games that are not arcade makecode

---

<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 3, 2023, 9:24pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/10 "2023-04-03T21:24:28Z")

</div>

Thank you! It was an idea I had for a very long time now, just never brought myself to do it…  
After all, it only took 20 minutes to put together the code for it so I don’t know what held me back for all that time. I’m guessing it’s the fact that I’m at my prime regarding TS and JS as I’m a lot better at working with them but also understanding their components.  
Anyway, this was sort of a quick util idea I came up with, if you have any other cool ideas for helpful extensions you’d want someone to make, you can always reach out! I love making extensions that help the community.

P.S: If I accumulate enough of these utility extensions in the following months, I might make them all into one big collection/compilation extension!

---

<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 3, 2023, 9:26pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/11 "2023-04-03T21:26:50Z")

</div>

If you’re refering to the whole post, it’s a bit of a complicated extension. Seeing as you’re new to MakeCode, it shouldn’t bother you too much at this stage.  
The primary idea is reducing the number of variables used. In bigger block projects, coders often create variables for temporary sprites (because sprites have to be stored somewhere), so that kind of creates a mess. Instead of that, with this extension you can create temporary sprites that behave just like regular sprites but don’t use variables. I hope this cleared up some things! If you have any further questions, lmk!

---

<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 3, 2023, 9:27pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/12 "2023-04-03T21:27:07Z")

</div>

Thank you everyone so much once again for the overwhelming support on this! I’m glad people find it useful!

> [@AbstractDesigner](#):
>
> I can’t wait to have Speedun fixed! (｡･ω･｡)

I’m releasing my next extension by the end of this week for sure, since my spring break starts on thursday, so I’ll be getting straight back into GameDev and that includes helping you as well as some other projects on the side, my own or not

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [April 3, 2023, 10:50pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/13 "2023-04-03T22:50:29Z")

</div>

I love this extension! It’s very well coded and very helpful! I’ve had some games where it seemed that I had reached a variable limit, so this will be great for that! I’m already using it in one of my games I’m making! (I’ll make sure to credit you when I release the game.)

---

<div class="post-metadata">

**Author:** ![Unique](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unique/32/32724_2.png) [@Unique](https://forum.makecode.com/u/Unique)\
**Post date:** [April 3, 2023, 10:51pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/14 "2023-04-03T22:51:26Z")

</div>

I have recently been working on a similar extension coincidentally, it’s variables rather then sprites.

But I do actually have a question, for some reason I haven’t been able to figure this one out.

> [@Sarge](#):
>
> ![Get sprite](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/ec3b5500c2b4b575a795406e33ffb828428bd56a.png)

How do you add a string input to a block like this (I forgot what these are called)?

---

<div class="post-metadata">

**Author:** ![ChimbroDaPro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chimbrodapro/32/15852_2.png) [@ChimbroDaPro](https://forum.makecode.com/u/ChimbroDaPro)\
**Post date:** [April 4, 2023, 3:06pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/15 "2023-04-04T15:06:34Z")

</div>

Okie. 🙂

---

<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 4, 2023, 3:07pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/16 "2023-04-04T15:07:28Z")

</div>

Assuming a function named `foo`, and string argument `bar`:

```auto
function foo(bar: string) {
    // do something
}

```

Adding the `//% block` formatting will automatically turn it into a text field.

If you want to use it in a custom block arrangement you’d use $bar within the block tag.

```auto
//% block="example $bar"
function foo(bar: string) {
...

```

Finally, you can add default values or shadow blocks to your text input like this:

```auto
//% bar.defl = <value>
or
//% bar.shadow = <shadow>

```

For more info see

> **[Defining blocks](https://makecode.com/defining-blocks)**
>
> This section describes how to annotate your MakeCode APIs to expose them in the Block Editor.

[https://makecode.com/playground](https://makecode.com/playground)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![ChimbroDaPro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chimbrodapro/32/15852_2.png) [@ChimbroDaPro](https://forum.makecode.com/u/ChimbroDaPro)\
**Post date:** [April 10, 2023, 5:33pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/17 "2023-04-10T17:33:15Z")

</div>

I think I get it… (nvm lol)

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [September 20, 2023, 8:35pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/18 "2023-09-20T20:35:53Z")

</div>

I feel like it’s almost impossible for me to make a game without this extension now… 😆 Same goes for the BetterSettings extension!

---

<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:** [September 20, 2023, 8:39pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/19 "2023-09-20T20:39:05Z")

</div>

Haha that’s good to hear, since I was kind of losing faith. I must admit I have stopped using this extension, so it’s good someone still finds it useful 😃

---

<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:** [September 20, 2023, 9:07pm UTC](https://forum.makecode.com/t/extension-declutter-your-variables/18813/20 "2023-09-20T21:07:40Z")

</div>

> [@Sarge](#):
>
> will throw a sprite stack extension

umm… this was supposed to say, throw an exception, not extension, lol 😆

[Next page](https://forum.makecode.com/t/extension-declutter-your-variables/18813.md?page=2)
