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

Here is the game code 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

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

This should work.

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

1 Like

If you set a variable like this:

let move = true

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

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.

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

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

1 Like

Like when no button is being pressed?

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

1 Like
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.

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

1 Like

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