# I'm probably doing something wrong

**URL:** https://forum.makecode.com/t/im-probably-doing-something-wrong/2781
**Category:** Help
**Created:** [July 15, 2020, 1:24am UTC](https://forum.makecode.com/t/im-probably-doing-something-wrong/2781 "2020-07-15T01:24:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)
#### Post date: [July 15, 2020, 1:24am UTC](https://forum.makecode.com/t/im-probably-doing-something-wrong/2781/1 "2020-07-15T01:24:10Z")

</div>

In [this program](https://makecode.com/_5MJYwEW7EYKV), I have an array of images stored in a variable called `frames`. I wrote some code to manually update my sprite’s image in a `game.onUpdate` based on some tick counting.

In `onUpdate`, if I reference the array of images through closure, it seems to run fine.

However, if I attempt to read the array of images off of my sprite’s custom data\*, there’s a crash in the runtime.

I’m sure this represents a misunderstanding on my part, but I’d love some help understanding what I’m doing wrong. (cc @jwunderl)

\*comment out `65` and uncomment `68`

---

<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: [July 15, 2020, 4:30am UTC](https://forum.makecode.com/t/im-probably-doing-something-wrong/2781/2 "2020-07-15T04:30:45Z")

</div>

Hmmm, weird. Looks like it’s not identifying it as an array properly if it’s stored in ‘any’. Giving a type hint fixes this: [https://makecode.com/\_KHv65WWkDFa6](https://makecode.com/_KHv65WWkDFa6)

@mmoskal is this expected / known behavior? I’m guessing just not identifying as an array vs an object literal?

Quick note, the data field is a [getter](https://github.com/microsoft/pxt-common-packages/blob/master/libs/game/sprite.ts#L161) so you should just be accessing as `mySprite.data` like you would `.x` and `.y`, without parens. I’m guessing this means we probably have wonky behavior if you have a getter returning a function, hmmm…

---

<div class="post-metadata">

### Author: ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)
#### Post date: [July 15, 2020, 4:56am UTC](https://forum.makecode.com/t/im-probably-doing-something-wrong/2781/3 "2020-07-15T04:56:29Z")

</div>

> [@jwunderl](#):
>
> the data field is a [getter](https://github.com/microsoft/pxt-common-packages/blob/master/libs/game/sprite.ts#L161)

… of course it is. Thanks.

I think that code was [inspired by code in the sprite data extension](https://github.com/microsoft/arcade-sprite-data/blob/master/main.ts#L11) which… ahem… also invokes `data` like a method.

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [July 15, 2020, 7:15am UTC](https://forum.makecode.com/t/im-probably-doing-something-wrong/2781/4 "2020-07-15T07:15:27Z")

</div>

> [@jwunderl](#):
>
> the data field is a [getter](https://github.com/microsoft/pxt-common-packages/blob/master/libs/game/sprite.ts#L161) so

Oopsy fixed.

---

<div class="post-metadata">

### Author: ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)
#### Post date: [July 15, 2020, 10:34am UTC](https://forum.makecode.com/t/im-probably-doing-something-wrong/2781/5 "2020-07-15T10:34:28Z")

</div>

It works if you do it like this:

```auto
    const animation = mySprite.data.animation as Image[]

```

In other words the compiler has to know that animation is an array.

I submitted [https://github.com/microsoft/pxt-arcade/issues/2161](https://github.com/microsoft/pxt-arcade/issues/2161) but I think this will be non-trivial to fix, so don’t hold your breath.

---

<div class="post-metadata">

### Author: ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)
#### Post date: [July 15, 2020, 12:01pm UTC](https://forum.makecode.com/t/im-probably-doing-something-wrong/2781/6 "2020-07-15T12:01:40Z")

</div>

As for `.data()`, see [https://github.com/microsoft/pxt/pull/7317](https://github.com/microsoft/pxt/pull/7317)
