# Store functions in arrays

**URL:** https://forum.makecode.com/t/store-functions-in-arrays/29313
**Category:** Help
**Tags:** extension, game
**Created:** [June 17, 2024, 10:46pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313 "2024-06-17T22:46:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![anon30657772](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@anon30657772](https://forum.makecode.com/u/anon30657772)
#### Post date: [June 17, 2024, 10:46pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313/1 "2024-06-17T22:46:19Z")

</div>

Hello! 😀

Anyone know an extension or a way to store functions inside an array? This means that I can use a “call” block and a “list get value at” block together to call a function at a given index?

> **Here's a picture example!**
>
> ![Example](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/1df5e0a3a2bf20748c58e8520b2fb255c679a825.png)
> 
> Forgive the low resolution 😅 Should’ve probably zoomed in more before taking the screenshots ahaha

---

<div class="post-metadata">

### Author: ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)
#### Post date: [June 17, 2024, 11:21pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313/2 "2024-06-17T23:21:18Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/9701581c7fcecf41bfd32f42d8eef6ce78b91d8b.png)  
returnng a value makes the function able to be used as this V  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/159614f535e4703c49305b285aa4b4e35eaa5a97.png)  
which can be used in an array

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [June 17, 2024, 11:26pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313/3 "2024-06-17T23:26:54Z")

</div>

@anon30657772 there’s no built in way to do this, but you could create an extension to make this work.

typings might be weird though… but if the function doesn’t need to have parameters or return values then I could make an extension for it real quick

can you share an example function?

---

<div class="post-metadata">

### Author: ![anon30657772](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@anon30657772](https://forum.makecode.com/u/anon30657772)
#### Post date: [June 17, 2024, 11:53pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313/4 "2024-06-17T23:53:35Z")

</div>

Yes but that would store the return value of the function, not the function itself!

---

<div class="post-metadata">

### Author: ![anon30657772](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@anon30657772](https://forum.makecode.com/u/anon30657772)
#### Post date: [June 17, 2024, 11:53pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313/5 "2024-06-17T23:53:36Z")

</div>

For the purpose of my game, the functions have different number and types of arguments 🥲

I appreciate the offer! I’ll work on it myself though since it seems to be a good excuse to make an extension and learn typescript 😜

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [June 17, 2024, 11:54pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313/6 "2024-06-17T23:54:50Z")

</div>

@anon30657772 check out [https://makecode.com/defining-blocks](https://makecode.com/defining-blocks) and feel free to @ me if you have any questions!

---

<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: [June 18, 2024, 4:24pm UTC](https://forum.makecode.com/t/store-functions-in-arrays/29313/7 "2024-06-18T16:24:06Z")

</div>

Hmm, I could try and pull this off
