# Array of ALL sprites?

**URL:** <https://forum.makecode.com/t/array-of-all-sprites/4922>\
**Category:** Help\
**Created:** [December 10, 2020, 10:28pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922 "2020-12-10T22:28:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [December 10, 2020, 10:28pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/1 "2020-12-10T22:28:58Z")

</div>

I know “array of sprite kind”, but how can I do “array of all sprites”?

---

<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:** [December 10, 2020, 10:47pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/2 "2020-12-10T22:47:37Z")

</div>

Easy to do in JavaScript, but tough to do in blocks.

In JavaScript:

```typescript
function getAllSprites() {
    const allSprites: Sprite[] = [];

    for (const key of Object.keys(game.currentScene().spritesByKind)) {
        for (const sprite of game.currentScene().spritesByKind[parseInt(key)].sprites()) {
            allSprites.push(sprite);
        }
    }
    return allSprites;
}

```

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [December 11, 2020, 12:14am UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/3 "2020-12-11T00:14:09Z")

</div>

Thanks! I’ll stick to JavaScript.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [December 11, 2020, 4:03am UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/4 "2020-12-11T04:03:31Z")

</div>

We need a block for this 😃

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [December 11, 2020, 6:17pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/5 "2020-12-11T18:17:47Z")

</div>

Good idea. That list will also include the player. Still you could check within the array if the sprite.kind is that of the player and skip doing something.

---

<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 16, 2021, 6:35pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/6 "2021-02-16T18:35:31Z")

</div>

> [@richard](#):
>
> ```auto
> function getAllSprites() {
> const allSprites: Sprite[] = [];
> 
> for (const key of Object.keys(game.currentScene().spritesByKind)) {
> for (const sprite of game.currentScene().spritesByKind[parseInt(key)].sprites()) {
> allSprites.push(sprite);
> }
> }
> return allSprites;
> }
> 
> ```

`Property 'Push' does not exist on type 'number'`  
Why does this happens. I just copied and pasted in, but still will not work…

---

<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:** [February 16, 2021, 6:47pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/7 "2021-02-16T18:47:22Z")

</div>

Can you share your project?

---

<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 16, 2021, 6:59pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/8 "2021-02-16T18:59:19Z")

</div>

I really just pasted it, I don’t know how that happened, It happens on anything though, not just that project.  
EDIT: it only happens in the offline app…  
@richard

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [February 16, 2021, 7:07pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/9 "2021-02-16T19:07:22Z")

</div>

I came up with this… put the arrays in an array… well this happens…(read the error thing)

> **[Array of all](https://arcade.makecode.com/59530-91104-16075-35663)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Also I realised that sometimes all pictures go blank… (bug) I think when you have an error and press on the error sign! I will do an experiment about it and tell you!

---

<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:** [February 16, 2021, 7:09pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/10 "2021-02-16T19:09:40Z")

</div>

@DahbixLP that code is actually creating an array of arrays of sprites. In other words, it’s an array where each of the items is another array.

---

<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 16, 2021, 7:50pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/11 "2021-02-16T19:50:38Z")

</div>

> **[GitHub - agent14bricks/array-of-all-sprites-extension: Will create a block...](https://github.com/agent14bricks/array-of-all-sprites-extension)**
>
> Will create a block that gathers all sprites onto one array. I used @richard 's code - GitHub - agent14bricks/array-of-all-sprites-extension: Will create a block that gathers all sprites onto o...

Just took @richard’s code.

> [@cosmoscowboy](#):
>
> Still you could check within the array if the sprite.kind is that of the player and skip doing something.

I may try this…

---

<div class="post-metadata">

**Author:** ![xavvvvvv](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/xavvvvvv/32/15324_2.png) [@xavvvvvv](https://forum.makecode.com/u/xavvvvvv)\
**Post date:** [February 16, 2021, 10:11pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/12 "2021-02-16T22:11:12Z")

</div>

Noice

---

<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 16, 2021, 10:14pm UTC](https://forum.makecode.com/t/array-of-all-sprites/4922/13 "2021-02-16T22:14:09Z")

</div>

Wiat don’t it will break your project for some reason…
