# Splash/Long Text showing up multiple times

**URL:** https://forum.makecode.com/t/splash-long-text-showing-up-multiple-times/13293
**Category:** Help
**Tags:** extension, game
**Created:** [April 27, 2022, 5:19pm UTC](https://forum.makecode.com/t/splash-long-text-showing-up-multiple-times/13293 "2022-04-27T17:19:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![brandodon](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/brandodon/32/3625_2.png) [@brandodon](https://forum.makecode.com/u/brandodon)
#### Post date: [April 27, 2022, 5:19pm UTC](https://forum.makecode.com/t/splash-long-text-showing-up-multiple-times/13293/1 "2022-04-27T17:19:06Z")

</div>

I am using the block menu extension and for some reason, sometimes whenever I choose an option that splashes a message or shows a Long text, it spams it 1-6 times, even though I disable the controls for 200 ms before.

```auto
if (index == 1) {
           blockMenu.closeMenu()
           blockMenu.setControlsEnabled(false)
           pause(200)
           game.showLongText("hi", DialogLayout.Full)
       }
```

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [April 27, 2022, 5:20pm UTC](https://forum.makecode.com/t/splash-long-text-showing-up-multiple-times/13293/2 "2022-04-27T17:20:57Z")

</div>

Could you share the full event that this occurs within? e.g. controller event, etc.

There’s a good chance that the issue is that the event is being queued by the event occurring multiple times before the text is displayed.

---

<div class="post-metadata">

### Author: ![brandodon](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/brandodon/32/3625_2.png) [@brandodon](https://forum.makecode.com/u/brandodon)
#### Post date: [April 28, 2022, 6:12pm UTC](https://forum.makecode.com/t/splash-long-text-showing-up-multiple-times/13293/3 "2022-04-28T18:12:21Z")

</div>

so basically first you press a button and it triggers a menu function

```auto
controller.menu.onEvent(ControllerButtonEvent.Pressed, function() {
    if (canPress = true) {
    Menu()
    }
})

```

then after the menu function

```auto
function Menu() {
    if (!guest) {
    blockMenu.setControlsEnabled(true)
    blockMenu.setColors(prim, sec)
    blockMenu.showMenu(["$100: Buy Case", "Inventory", "Stats", "Value List", "$500: Money Multiplier (" + moneyMultiplier + ")", "$500: Clickers (" + clickers + ")", "$300: Click Rate (" + clickRate + ")", "Save Game (Overwrites!!)", "Delete Game", "Close"], MenuStyle.List, MenuLocation.FullScreen)
    blockMenu.onMenuOptionSelected(function(option, index) {
        if (index == 0) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            pause(50)
            Buy()
        }
        if (index == 1) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            pause(200)
            game.showLongText("Coal: " + coal + ". Copper: " + copper + ". Iron: " + iron + ". Gold: " + gold + ". Lapis " + lapis + ". Turquoise: " + turquoise + ". Teal: " + teal + ". Amethyst: " + amethyst + ". Emerald: " + emerald + ". Ruby: " + ruby + ". Diamond: " + diamond + ".", DialogLayout.Full)
        }
        if (index == 2) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            pause(200)
            game.showLongText("Money: " + info.score() + ". Value: " + finalValue + ". Money multiplier: " + moneyMultiplier + ". Clickers: " + clickers + ". Click rate: " + clickRate + ".", DialogLayout.Full)
        }
        if (index == 3) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            pause(200)
            game.showLongText("Coal Value: $10. Copper Value: $35. Iron Value: $50. Gold: $80. Lapis: 85. Turquoise: 90. Teal: 100. Amethyst: 120. Emerald: 150. Ruby: 200. Diamond: 500", DialogLayout.Full)
        }
        if (index == 4) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            let quantity = game.askForNumber("Quantity", 3)
            if (info.score() < 500 * quantity) {
                game.splash("You cannot buy this item.")
            }
            else {
            info.changeScoreBy(-500 * quantity)
            moneyMultiplier += quantity
            game.splash("Your money multiplier is now " + moneyMultiplier)
            }
        }
        if (index == 5) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            let quantity = game.askForNumber("Quantity", 3)
            if (info.score() < 500 * quantity) {
                game.splash("You cannot buy this item.")
            }
            else {
            let currentValue = clickers
            info.changeScoreBy(-500 * quantity)
            clickers += 1 * quantity
            game.splash("The amount of clickers is now " + clickers)
            }
        }
        if (index == 6) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            if (info.score() < 300) {
                game.splash("You cannot buy this item.")
            }
            else {
                if (clickRate >= 0.5) {
                info.changeScoreBy(-300)
                clickRate += -0.5
                game.splash("Your click rate is now " + clickRate)
                }
                else {
                game.splash("You are at the max click rate.")
                }
            }
        }
        if (index == 7) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            if (!guest) {
            let pass2 = game.askForString("Password?", 18)
            if (pass2 == password) {
            blockSettings.writeNumber("sMoney", info.score())
            blockSettings.writeNumber("sPrimary", prim)
            blockSettings.writeNumber("sSecondary", sec)
            blockSettings.writeNumber("sBackground", bg)
            blockSettings.writeNumber("sClickers", clickers)
            blockSettings.writeNumber("sMultiplier", moneyMultiplier)
            blockSettings.writeNumber("sClickrate", clickRate)
            blockSettings.writeNumber("coals", coal)
            blockSettings.writeNumber("coppers", copper)
            blockSettings.writeNumber("irons", iron)
            blockSettings.writeNumber("golds", gold)
            blockSettings.writeNumber("lapiss", lapis)
            blockSettings.writeNumber("turquoises", turquoise)
            blockSettings.writeNumber("teals", teal)
            blockSettings.writeNumber("amethysts", amethyst)
            blockSettings.writeNumber("emeralds", emerald)
            blockSettings.writeNumber("rubys", ruby)
            blockSettings.writeNumber("diamonds", diamond)
            game.splash("Game saved.")
            }
        }
        else {
            game.splash("Can't save on guest account.")
        }
        }
        if (index == 8) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
            if (!guest) {
                let pass2 = game.askForString("Password? (this deletes everything including name and password!)", 18)
                if (pass2 == password) {
                    blockSettings.clear()
                    game.splash("All progress cleared :(")
                }
            }
            else {
                game.splash("You don't have an account to delete.")
            }
        }
        if (index == 9) {
            blockMenu.closeMenu()
            blockMenu.setControlsEnabled(false)
        }
    })
    }
}

```

there are many indexes,

this is from my game [Gem Clicker](https://arcade.makecode.com/83970-24844-92241-04477)/[Ore Clicker](https://forum.makecode.com/t/ore-clicker/13176) and I’ve been having issues with this.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [April 28, 2022, 9:17pm UTC](https://forum.makecode.com/t/splash-long-text-showing-up-multiple-times/13293/4 "2022-04-28T21:17:41Z")

</div>

```nohighlight
    if (canPress = true) {
        Menu()
    }

```

By the way, that will always evaluate to `true` because you are using the assignment operator (`=`) instead of the equality check operator. (`==`) Use `if (canPress == true) {` or `if (canPress) {`.

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [April 29, 2022, 12:27am UTC](https://forum.makecode.com/t/splash-long-text-showing-up-multiple-times/13293/5 "2022-04-29T00:27:29Z")

</div>

Ah, I see. I think the issue is actually that `blockMenu.onMenuOptionSelected` is being registered inside the function – it looks like that can be called multiple times to register difference behaviors (for example, that could be if you had something like separating out each index into it’s own handler).

In this case, that means that the first time you open the menu and select something it will run the event one time; the second time you open the menu select something it will reregister the event and thus run two times, then three times and so on.

If you separate it out like this:

```typescript
controller.menu.onEvent(ControllerButtonEvent.Pressed, function() {
    if (canPress) {
    Menu()
    }
})

function Menu() {
    if (!guest) {
        blockMenu.setControlsEnabled(true)
        blockMenu.setColors(prim, sec)
        blockMenu.showMenu(["$100: Buy Case", "Inventory", "Stats", "Value List", "$500: Money Multiplier (" + moneyMultiplier + ")", "$500: Clickers (" + clickers + ")", "$300: Click Rate (" + clickRate + ")", "Save Game (Overwrites!!)", "Close"], MenuStyle.List, MenuLocation.FullScreen)
    }
}

blockMenu.onMenuOptionSelected(function (option, index) {
    if (index == 0) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        pause(50)
        Buy()
    }
    if (index == 1) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        pause(200)
        game.showLongText("Coal: " + coal + ". Copper: " + copper + ". Iron: " + iron + ". Gold: " + gold + ". Lapis " + lapis + ". Turquoise: " + turquoise + ". Teal: " + teal + ". Amethyst: " + amethyst + ". Emerald: " + emerald + ". Ruby: " + ruby + ". Diamond: " + diamond + ".", DialogLayout.Full)
    }
    if (index == 2) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        pause(200)
        game.showLongText("Money: " + info.score() + ". Value: " + finalValue + ". Money multiplier: " + moneyMultiplier + ". Clickers: " + clickers + ". Click rate: " + clickRate + ".", DialogLayout.Full)
    }
    if (index == 3) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        pause(200)
        game.showLongText("Coal Value: $10. Copper Value: $35. Iron Value: $50. Gold: $80. Lapis: 85. Turquoise: 90. Teal: 100. Amethyst: 120. Emerald: 150. Ruby: 200. Diamond: 500", DialogLayout.Full)
    }
    if (index == 4) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        let quantity = game.askForNumber("Quantity", 3)
        if (info.score() < 500 * quantity) {
            game.splash("You cannot buy this item.")
        }
        else {
            info.changeScoreBy(-500 * quantity)
            moneyMultiplier += quantity
            game.splash("Your money multiplier is now " + moneyMultiplier)
        }
    }
    if (index == 5) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        let quantity = game.askForNumber("Quantity", 3)
        if (info.score() < 500 * quantity) {
            game.splash("You cannot buy this item.")
        }
        else {
            let currentValue = clickers
            info.changeScoreBy(-500 * quantity)
            clickers += 1 * quantity
            game.splash("The amount of clickers is now " + clickers)
        }
    }
    if (index == 6) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        if (info.score() < 300) {
            game.splash("You cannot buy this item.")
        }
        else {
            if (clickRate >= 0.5) {
                info.changeScoreBy(-300)
                clickRate += -0.5
                game.splash("Your click rate is now " + clickRate)
            }
            else {
                game.splash("You are at the max click rate.")
            }
        }
    }
    if (index == 7) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
        if (!guest) {
            let pass2 = game.askForString("Password?", 18)
            if (pass2 == password) {
                blockSettings.writeNumber("sMoney", info.score())
                blockSettings.writeNumber("sPrimary", prim)
                blockSettings.writeNumber("sSecondary", sec)
                blockSettings.writeNumber("sBackground", bg)
                blockSettings.writeNumber("sClickers", clickers)
                blockSettings.writeNumber("sMultiplier", moneyMultiplier)
                blockSettings.writeNumber("sClickrate", clickRate)
                blockSettings.writeNumber("coals", coal)
                blockSettings.writeNumber("coppers", copper)
                blockSettings.writeNumber("irons", iron)
                blockSettings.writeNumber("golds", gold)
                blockSettings.writeNumber("lapiss", lapis)
                blockSettings.writeNumber("turquoises", turquoise)
                blockSettings.writeNumber("teals", teal)
                blockSettings.writeNumber("amethysts", amethyst)
                blockSettings.writeNumber("emeralds", emerald)
                blockSettings.writeNumber("rubys", ruby)
                blockSettings.writeNumber("diamonds", diamond)
                game.splash("Game saved.")
            }
        }
        else {
            game.splash("Can't save on guest account.")
        }
    }
    if (index == 8) {
        blockMenu.closeMenu()
        blockMenu.setControlsEnabled(false)
    }

})

```

then it should behave as you want. (note that I did also fix the bug unsignedarduino pointed out, where it was behaving like an ‘if (true)’)
