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:
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)’)