[SOLVED] Character Selection Menu Issue

How do I…

Make a working character selection menu?

What is the expected result

I want my characters to cycle when pressing “A” or “D”, and depending on which value you are (what character is currently selected), it will send you to the next or either previous character.
For example, I have 3 characters in this occasion.

If I press “D” and the last (3rd) character is selected, go to the first
If I pres “A” and the first character is selected, go to the last (3rd)

What is the actual result

It just ends up bugging. When I press “A” while in the first character, instead of going to the 3rd, I go to the 2nd. Same thing backwards: When I press “D” while in the 3rd character, instead of going to the first, I go to the 2nd. Here’s a gif, showing the problem in action:

ezgif.com-gif-maker

Focus on the lower-left corner, that number is the “personagemSelecionado” variable.
The rest doesn’t really matter that much, only the sprites in the center that show which is the current selected character.

Related screenshots

Just to clarify, “personagemSelecionado” meanst the current selected character, and “totalPersonagens” means the total amount of characters to select -1 (In this case, I have 3 characters, so the total amount is 2)

personagemSelecionado = Current selected character in the menu
totalPersonagens = 2

Hi,
Here what happens:
If A key is pressed:

  • If selectedcharacter=0, it set it to numberofcharacters
  • If selectedcharacter=numberofcharacters, (and that’s the case now! Here is your problem), substract 1.

Your variable was at 0, it has been put to 3 as expected but directly after, substract 1.
So end up being 2.

Same problem occures in the press D event.

I think you can easily fix it. Invert the two events:
In press A events: first substract 1, and THEN, if =0, set it to numberofcharacters.

Same for D events.

1 Like