# Binary Gardening- help needed

**URL:** <https://forum.makecode.com/t/binary-gardening-help-needed/37470>\
**Category:** Help\
**Created:** [June 22, 2025, 2:52am UTC](https://forum.makecode.com/t/binary-gardening-help-needed/37470 "2025-06-22T02:52:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![butterflymoon](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@butterflymoon](https://forum.makecode.com/u/butterflymoon)\
**Post date:** [June 22, 2025, 2:52am UTC](https://forum.makecode.com/t/binary-gardening-help-needed/37470/1 "2025-06-22T02:52:57Z")

</div>

Hi, I’m making a game and I need help cus it’s not working. The part that isn’t working is a part of the tutorial. The basic concept of the game, for reference, is that each turn you water the tree to make it grow and you try to get points. The tutorial explains more. In the second part of the tutorial I wanted to let the player try cutting a leaf, but it doesn’t work. Here’s the code for that part:

 ![Screenshot 2025-06-22 111836](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/6/a/6ae0d639e9a2701c4e6e16c1cb5d0486e0111afc.png)

I originally used pause until is B button pressed and cursor hitbox overlaps with leaf, but that didn’t work. It was because the leaf variable was only associated with the latest created sprite using the leaf variable. So I searched online and the code in the screenshot is apparently an alternative. But it doesn’t let me move my cursor (in the game) when it gets up to here.

Here’s [my game](https://makecode.com/_K8U1VW8vhXRL) so you can look at the other code.

Thank you to anyone who replies :D.

---

<div class="post-metadata">

**Author:** ![butterflymoon](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@butterflymoon](https://forum.makecode.com/u/butterflymoon)\
**Post date:** [June 22, 2025, 4:17pm UTC](https://forum.makecode.com/t/binary-gardening-help-needed/37470/2 "2025-06-22T16:17:08Z")

</div>

Update:  
I tried testing the game without the while loop, and I could move the cursor, so maybe the while loop disables control buttons?

 ![Screenshot 2025-06-22 143439](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/3/0/308b2bee959141cb2c1e09243a3c249d9191a503.png)

---

<div class="post-metadata">

**Author:** ![a012](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/a012/32/24099_2.png) [@a012](https://forum.makecode.com/u/a012)\
**Post date:** [August 28, 2025, 4:49am UTC](https://forum.makecode.com/t/binary-gardening-help-needed/37470/3 "2025-08-28T04:49:07Z")

</div>

> [@butterflymoon](#):
>
> I originally used pause until is B button pressed and cursor hitbox overlaps with leaf, but that didn’t work. It was because the leaf variable was only associated with the latest created sprite using the leaf variable. So I searched online and the code in the screenshot is apparently an alternative. But it doesn’t let me move my cursor (in the game) when it gets up to here.
> 
> Here’s [my game](https://makecode.com/_K8U1VW8vhXRL) so you can look at the other code.
> 
> Thank you to anyone who replies :D.

Ahhh I see exactly what’s going on, this is one of those MakeCode “tricky async/blocking” things that confuses everyone at first. I’ll break it down:

* * *

### 🔹 Problem

In `Try_2()` you have:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/7/0/70411446035c4ddcc1caeb1a0e9c4c8ca64c838c.png)

The problem here is that `while` loops **freeze the game update loop**. MakeCode runs `game.onUpdate()` and controller checks **frame by frame** , but your `while` loop hogs the thread. That’s why your cursor won’t move: the game is stuck inside that loop and **controller input doesn’t get processed**.

Also, `pauseUntil()` has the same problem:

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/optimized/3X/d/0/d009fb4a6dcfaeb78895783980a3d26b5085daf6_2_690x40.png)

It **pauses everything else** , so sprites, animations, and movement stop until the condition is true.

* * *

### 🔹 Why your previous “leaf variable only stores the last created sprite” issue happened

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/8/0/805e51faec642cf000f9ad3acd3dbd380578404b.png)

Every time you do this, `leaf` points to **the latest leaf only**. All the previous leaves still exist, but `leaf` doesn’t reference them. That’s why looping over `sprites.allOfKind(SpriteKind.Leaf)` is correct—you need to check all leaves, not just one variable.

* * *

### 🔹 How to fix it

You should **avoid blocking loops** like `while` or `pauseUntil()` for player input. Instead, use **events or `game.onUpdate()` checks**:

```auto
game.onUpdate(function() {
    for (let value of sprites.allOfKind(SpriteKind.Leaf)) {
        if (controller.B.isPressed() && cursor_hitbox.overlapsWith(value)) {
            sprites.destroy(value, effects.ashes, 200)
            leaves -= 1
        }
    }
})

```

This way:

- The game keeps running.
- Cursor movement works.
- Multiple leaves can be cut at any time.

You can also combine it with a simple debounce if you don’t want `B` to destroy multiple leaves per frame:

```auto
let canCut = true

game.onUpdate(function() {
    if (controller.B.isPressed() && canCut) {
        for (let value of sprites.allOfKind(SpriteKind.Leaf)) {
            if (cursor_hitbox.overlapsWith(value)) {
                sprites.destroy(value, effects.ashes, 200)
                leaves -= 1
            }
        }
        canCut = false
    } else if (!controller.B.isPressed()) {
        canCut = true
    }
})

```

✅ That fixes the “game freezes / cursor can’t move” issue and handles **all leaves dynamically**.
