# Issues with While Loop in character select

**URL:** <https://forum.makecode.com/t/issues-with-while-loop-in-character-select/43959>\
**Category:** Help\
**Created:** [May 12, 2026, 6:00pm UTC](https://forum.makecode.com/t/issues-with-while-loop-in-character-select/43959 "2026-05-12T18:00:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pumpkinwearingsocks](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/pumpkinwearingsocks/32/19923_2.png) [@pumpkinwearingsocks](https://forum.makecode.com/u/pumpkinwearingsocks)\
**Post date:** [May 12, 2026, 6:00pm UTC](https://forum.makecode.com/t/issues-with-while-loop-in-character-select/43959/1 "2026-05-12T18:00:43Z")

</div>

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.

```javascript
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?

---

<div class="post-metadata">

**Author:** ![redSprite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/redsprite/32/34262_2.png) [@redSprite](https://forum.makecode.com/u/redSprite)\
**Post date:** [May 12, 2026, 6:49pm UTC](https://forum.makecode.com/t/issues-with-while-loop-in-character-select/43959/2 "2026-05-12T18:49:24Z")

</div>

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.
