Issues with While Loop in character select

In a game I’m making, I’m trying to add a simple character select with both players pressing left or right to change characters and A to confirm. After both players have confirmed the game starts up as usual.

let p1confirm = false
let p2confirm = false
p1char = 1
p2char = 1
player1 = sprites.create(getStandRight(p1char), SpriteKind.Player)
player2 = sprites.create(getStandRight(p2char), SpriteKind.Player)
player1.setPosition(50, 60)
player2.setPosition(110, 60)
while (!(p1confirm && p2confirm)) {
    if (controller.left.isPressed()) {
        p1char --
    }
    if (controller.right.isPressed()) {
        p1char ++
    }
    if (controller.A.isPressed()){
        p1confirm = true
    }
    if (controller.player2.isPressed(ControllerButton.Left)) {
        p2char --
    }
    if (controller.player2.isPressed(ControllerButton.Right)) {
        p2char ++
    }
    if (controller.player2.isPressed(ControllerButton.A)) {
        p2confirm = true
    }
}
// Finish making game

However, when I add the while loop, it turns into a black screen and the sprites won’t display. Also, the screen doesn’t move on when both players press A.

If it helps, I have this code at the “on start” (or whatever the JavaScript equivalent is), and for convenience the player1 and player2 sprites are the same as the actual sprites during gameplay (before adding gravity and controls of course)

Can someone help me or show a workaround?

I think it’s because the “update” part of a frame is still happening as the while loop does it’s thing, causing nothing to be drawn.
Use the timer extension’s “Separately do”, perhaps that can help.

1 Like