# Trying to make a game that disables contoller movement when my statusbar value is 0

**URL:** <https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364>\
**Category:** Arcade\
**Created:** [February 28, 2024, 10:51pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364 "2024-02-28T22:51:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BioShrimpCoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bioshrimpcoding/32/13238_2.png) [@BioShrimpCoding](https://forum.makecode.com/u/BioShrimpCoding)\
**Post date:** [February 28, 2024, 10:51pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/1 "2024-02-28T22:51:55Z")

</div>

Here is the game code [https://arcade.makecode.com/S40735-24715-80484-55643](https://arcade.makecode.com/S40735-24715-80484-55643)

When the statusbar value hits zero I want to to disable controller movement or just sprite movement in general

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [February 29, 2024, 5:47pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/2 "2024-02-29T17:47:43Z")

</div>

```auto
statusbars.onZero(StatusBarKind.Player1_Energy, function(status: StatusBarSprite) {
Ninja.setVelocity(0, 0)
})

```

This should work.

---

<div class="post-metadata">

**Author:** ![BioShrimpCoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bioshrimpcoding/32/13238_2.png) [@BioShrimpCoding](https://forum.makecode.com/u/BioShrimpCoding)\
**Post date:** [February 29, 2024, 11:31pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/3 "2024-02-29T23:31:41Z")

</div>

I tried using that before but the sprite still moves and I’m thinking of adding my own extension that adds something like controller.moveSprite(Sprite Name, True) the only problem is I don’t know how to code ar make my own extensions that could work with blocks or even makecode arcade javascript

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [March 1, 2024, 7:09pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/4 "2024-03-01T19:09:24Z")

</div>

If you set a variable like this:

```auto
let move = true

```

then you can use the variable to control when the sprite moves.

```auto
controller.left.onEvent(ControllerButtonEvent.Pressed, function () {
    if (move === true) {
        direction = "left"
        Ninja.setVelocity(-50, 0)
    }  
})

```

And you can set the variable to `false` when the energy bar hits 0.

```auto
statusbars.onZero(StatusBarKind.Player1_Energy, function(status: StatusBarSprite) {
    move = false
    Ninja.setVelocity(0, 0)
})

```

---

<div class="post-metadata">

**Author:** ![BioShrimpCoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bioshrimpcoding/32/13238_2.png) [@BioShrimpCoding](https://forum.makecode.com/u/BioShrimpCoding)\
**Post date:** [March 1, 2024, 10:24pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/5 "2024-03-01T22:24:31Z")

</div>

it works now The only thing I need is for it to not move when there is no input

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [March 4, 2024, 7:19pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/6 "2024-03-04T19:19:58Z")

</div>

Like when no button is being pressed?

---

<div class="post-metadata">

**Author:** ![BioShrimpCoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bioshrimpcoding/32/13238_2.png) [@BioShrimpCoding](https://forum.makecode.com/u/BioShrimpCoding)\
**Post date:** [March 4, 2024, 10:17pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/7 "2024-03-04T22:17:32Z")

</div>

Yes I don’t want the sprite to move when there is no input and only to move when there is one like in Minecraft you only move forward when you pressing W

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [March 5, 2024, 7:37pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/8 "2024-03-05T19:37:21Z")

</div>

```auto
controller.left.onEvent(ControllerButtonEvent.Repeated, function () {
    if (move === true) {
        direction = "left"
        Ninja.setVelocity(-50, 0)
    }  
})

controller.left.onEvent(ControllerButtonEvent.Released, function() {
Ninja.setVelocity(0, 0)
})

```

This should work! Just modify your current movement block to `repeated` instead of `pressed`, and then add the `released` event block.

---

<div class="post-metadata">

**Author:** ![BioShrimpCoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bioshrimpcoding/32/13238_2.png) [@BioShrimpCoding](https://forum.makecode.com/u/BioShrimpCoding)\
**Post date:** [March 5, 2024, 11:35pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/9 "2024-03-05T23:35:44Z")

</div>

ok so it works but you want it like this  
controller.left.onEvent(ControllerButtonEvent.Repeated, function () {  
if (move === true) {  
direction = “left”  
Ninja.setVelocity(-50, 0)  
}  
})

controller.left.onEvent(ControllerButtonEvent.Released, function () {  
Ninja.setVelocity(0, 0)  
})

controller.left.onEvent(ControllerButtonEvent.Pressed, function () {  
if (move === true) {  
direction = “left”  
Ninja.setVelocity(-50, 0)  
}  
})

because if you don’t have the pressed one it waits a few seconds

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [March 6, 2024, 6:31pm UTC](https://forum.makecode.com/t/trying-to-make-a-game-that-disables-contoller-movement-when-my-statusbar-value-is-0/27364/10 "2024-03-06T18:31:51Z")

</div>

Well, you can switch the code around a bit to find what works best for you.
