# Why does my extension block not work?

**URL:** <https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506>\
**Category:** Help\
**Created:** [January 12, 2021, 8:44pm UTC](https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506 "2021-01-12T20:44:45Z")\
**Posts on this page:** 6\
**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:** [January 12, 2021, 8:44pm UTC](https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506/1 "2021-01-12T20:44:45Z")

</div>

> **[Costom Fonts](https://arcade.makecode.com/17923-41344-27868-17941)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Yes, I made a custom font extension. Well, almost. This block doesn’t work -

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/f397c6b359b8cfd8e240de47da012379f937093e.png)  
This block is supposed to set an image to a string in a particular font.

Here is the code for that block -

```
//%block="set $output=variables_get(picture) to $input"
export function SetImage(output: Image, input: string) {
    let heig = 0
    let widt = 0
    let curwidt = 0

    for (let currentletter = 0; currentletter <= input.length; currentletter++) {

        if (!(ligs.indexOf(input.charAt(currentletter)) == -1)) {
            heig = Math.max(heig, ligages[(ligs.indexOf(input.charAt(currentletter)))].height)
        }
    }

    for (let currentletter2 = 0; currentletter2 <= input.length; currentletter2++) {
        if (!(ligs.indexOf(input.charAt(currentletter2)) == -1)) {
            widt += ligages[(ligs.indexOf(input.charAt(currentletter2)))].width
        } else if (input.charAt(currentletter2) == " ") {
            widt += 3*letterspace
        }
        widt += 1
    }

    output = image.create(widt, heig)
    for (let currentletter3 = 0; currentletter3 <= input.length; currentletter3++) {

        if (!(ligs.indexOf(input.charAt(currentletter3)) == -1)) {
            drawTransparentImage(ligages[(ligs.indexOf(input.charAt(currentletter3)))], output, curwidt, 3)
            curwidt += letterspace
            curwidt += ligages[(ligs.indexOf(input.charAt(currentletter3)))].width
        }
    }

}

```

Can someone explain why it doesn’t work? @richard, was it you who made the text sprite extension? I used some code from there, that might be where it went wrong.

---

<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:** [January 12, 2021, 11:00pm UTC](https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506/2 "2021-01-12T23:00:14Z")

</div>

Actually that extension was written by @darzu but I’m happy to help! Can you send the rest of the code?

---

<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:** [January 12, 2021, 11:03pm UTC](https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506/3 "2021-01-12T23:03:48Z")

</div>

Oh, the link is at the top!

---

<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:** [January 13, 2021, 12:19am UTC](https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506/4 "2021-01-13T00:19:19Z")

</div>

First, I think you want to use `<` and not `<=` in those for-loops. The main issue though is that you are creating a new image and drawing to that. The sprite is still pointing to the old image, so it won’t update. Either you should update your function to draw to the original image (which may be the wrong size) or you should change your function to return an image instead of taking one in. Then the user could use it like this:

```auto
sprite.setImage(Fonts.createImage("hello"))

```

---

<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:** [January 13, 2021, 12:29am UTC](https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506/5 "2021-01-13T00:29:59Z")

</div>

To clarify the variable point, it can help to think of variables as a sort of box. What’s inside the box in this case is a pointer to an Image. You can think of a pointer as an address where the image is stored.

The sprite has a box with the image pointer inside it, and when you call this function you’re creating a new box called “output” and putting the same pointer inside of it as the one in the sprite’s box.

When you write `output = image.create(widt, heig)`, you are putting a new pointer in the output box, but the sprite’s box (which is separate) isn’t changing.

Hopefully that’s helpful! I think I got lost in my own metaphor at some point.

---

<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:** [January 13, 2021, 2:15am UTC](https://forum.makecode.com/t/why-does-my-extension-block-not-work/5506/6 "2021-01-13T02:15:47Z")

</div>

Thanks, it worked! 😁

I’ll be posting the finished thing soon!
