# Help with extension

**URL:** https://forum.makecode.com/t/help-with-extension/45571
**Category:** Help
**Tags:** extension, graphics-and-math
**Created:** [August 24, 2026, 11:02pm UTC](https://forum.makecode.com/t/help-with-extension/45571 "2026-08-24T23:02:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Cybercube](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cybercube/32/34628_2.png) [@Cybercube](https://forum.makecode.com/u/Cybercube)
#### Post date: [August 24, 2026, 11:02pm UTC](https://forum.makecode.com/t/help-with-extension/45571/1 "2026-08-24T23:02:55Z")

</div>

so, i have so problem with my extensions but you choose what problem to help me with.

> **problem #1**
>
> So, i need help with my extension because when i put the variable in these blocks i won’t allow it so, here’s the code for the blocks:
> 
> ```auto
> //% block="On game update every $ms do if $tru"
> //% draggableParameters
> //% subcategory="Logic"
> export function GameUpdateEveryIf(ms: number, tru: Boolean, handler: () => void) {
> game.onUpdateInterval(ms, function() {
> if (tru) {
> handler();
> }
> })
> }
> 
> ```
> 
> ```auto
> 
> //% block="On game update if $tru"
> //% draggableParameters
> //% subcategory="Logic"
> export function GameUpdateIf(tru: Boolean, handler: () => void) {
> game.onUpdate(function() {
> if (tru) {
> handler();
> }
> })
> }
> 
> ```
> 
> ```auto
> 
> //% block="forever if $tru"
> //% subcategory="Logic"
> export function onEventAsStatement(tru: Boolean, handler: () => void) {
> forever(function() {
> if (tru) {
> handler();
> }
> })
> }
> 
> ```

> **problem #2**
>
> So how to you add a “+” button to the “false is -1 or 0: $toggle” ? heres the code:
> 
> ```auto
> 
> //% block="Convert $n|to number|false is -1 or 0: $toggle"
> //% subcategory="Logic"
> //% toggle.shadow="toggleYesNo"
> export function ConvertToNum(n: boolean, toggle: boolean) {
> if (n) {
> return CyberScripts.fib(toggle, 0, -1);
> } else {
> return 1;
> }
> }
> 
> //% block="if|$t then|$input1 else|$input2"
> //% subcategory="Logic"
> export function fib(t: boolean, input1: any, input2: any): any {
> if (t) {
> return input1;
> } else {
> return input2;
> }
> }
> 
> ```

---

<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: [August 25, 2026, 8:26pm UTC](https://forum.makecode.com/t/help-with-extension/45571/2 "2026-08-25T20:26:44Z")

</div>

if i’m reading this code right, it sounds like in problem 1 you’re trying to create a block that basically does this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/0/2/02e40959a92b782204f9c95b5f0cfe222afc9e0d.png)

where `someBooleanExpression` is an expression that could change over time.

well, that’s not possible. when you call a function with a boolean argument, the value of that boolean will be captured in the initial call and will never change.

if you wanted to do something like that in javascript, you would write your function like this:

```ts
function conditionalOnGameUpdate(condition: () => boolean, handler: () => void) {
    game.onGameUpdate(() => {
        if (condition()) {
            handler()
        }
    });
}

```

the condition argument in this example is a function that returns a boolean. that function gets called every frame and allows the expression to be re-evaluated.

unfortunately, while this is totally doable in javascript, there is no way to make a block that does this (actually there is one block that works this way and it’s [pause until](https://forum.makecode.com/t/richards-arcade-tips-3-the-pause-until-block/28794), but it’s special and you can’t replicate it in an extension)

as for problem 2, i have no idea what you’re trying to do here. can you draw a picture of what your block should look like and maybe give some sample code to show how it’s used?

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [August 25, 2026, 10:11pm UTC](https://forum.makecode.com/t/help-with-extension/45571/3 "2026-08-25T22:11:55Z")

</div>

here is `game.onUpdate`:

> <https://github.com/microsoft/pxt-common-packages/blob/31abf23d118f35010fb75122e60a1eb2b6dffe9f/libs/game/gameutil.ts#L14>

and `forever`:

> <https://github.com/microsoft/pxt-common-packages/blob/31abf23d118f35010fb75122e60a1eb2b6dffe9f/libs/base/forever.ts#L7>

---

<div class="post-metadata">

### Author: ![CodaKnight](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/codaknight/32/33491_2.png) [@CodaKnight](https://forum.makecode.com/u/CodaKnight)
#### Post date: [August 25, 2026, 10:12pm UTC](https://forum.makecode.com/t/help-with-extension/45571/4 "2026-08-25T22:12:34Z")

</div>

### Problem #1: Variables won’t plug into `$tru`

The main issue is this:

```typescript
tru: Boolean

```

For MakeCode/PXT block definitions, you generally want the **primitive TypeScript type** :

```typescript
tru: boolean

```

`Boolean` and `boolean` aren’t interchangeable for PXT’s block type inference. `Boolean` is the boxed JavaScript object type, while `boolean` is the actual primitive type that MakeCode recognizes as a Boolean input.

So change all three to:

```typescript
tru: boolean

```

(NOTE: maybe change tru to **condition** )

For example:

```typescript
//% block="On game update every $ms do if $tru"
//% draggableParameters
//% subcategory="Logic"
export function GameUpdateEveryIf(ms: number, tru: boolean, handler: () => void) {
    game.onUpdateInterval(ms, function () {
        if (tru) {
            handler()
        }
    })
}

```

And similarly:

```typescript
export function GameUpdateIf(tru: boolean, handler: () => void) {

```

and:

```typescript
export function onEventAsStatement(tru: boolean, handler: () => void) {

```

That should make the Boolean expression socket accept variables.

**One other thing:** if you’re trying to make `$tru` accept _any expression_ rather than specifically a Boolean, then the type needs to match what you actually want. But for a normal `true`/`false` socket, `boolean` is the right type.

* * *

### Problem #2: Adding a `+` button

For problem #2, yes, `expandableArgumentMode` is what you’re looking for. You can use `||` in the `//% block` definition to mark the start of the expandable argument section. For example:

```auto
//% block="set the motor to run || $direction|at $speed|for $duration ms"
//% expandableArgumentMode="enabled"

```

The `||` separates the regular part of the block from the expandable arguments, and `expandableArgumentMode="enabled"` enables the `+` button for that section.

So for the first problem, try `boolean` instead of `Boolean`, and for the second, use the `||` + `expandableArgumentMode="enabled"` combination.

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [August 25, 2026, 10:12pm UTC](https://forum.makecode.com/t/help-with-extension/45571/5 "2026-08-25T22:12:44Z")

</div>

> **1**
>
> here is the source code for [game.onUpdate](https://github.com/microsoft/pxt-common-packages/blob/31abf23d118f35010fb75122e60a1eb2b6dffe9f/libs/game/gameutil.ts#L14) and [forever](https://github.com/microsoft/pxt-common-packages/blob/31abf23d118f35010fb75122e60a1eb2b6dffe9f/libs/base/forever.ts#L7)

> **2**
>
> I don’t know why you have so much extra stuff, but are you thinking of something like this:
> 
> ```typescript
> //% block="Convert $n to number"
> //% subcategory="Logic"
> //% n.shadow="toggleYesNo"
> export function BToN(n: boolean) {
> return +n
> }
> 
> ```
> 
> ?
