I ran into a problem when creating a player icon selection. In the game, I need to make an icon selection when pressing the "S" key. To realize my idea, I decided to use the "AnimatedSprite2D" node, dividing the SpriteSheet of icons into 5 images (In my SpriteSheet there are 5 images for player icons) and creating a separate animation for each image. But when I got to the script, I ran into big problems. I do not know how to implement my idea so that when the "S" button is pressed, the next image is selected, and when the player reaches the fifth image, the list is updated and goes back to the first image. Please help me!!! If you have a more convenient solution without using "AnimatedSprite2D", feel free to suggest it. I also ask you to add the training materials that were used in writing your script. If it's not hard for you, you can explain your decision to me. Thank you so much in advance for your help!!!

    Scel "S" key.

    Scel "S" button

    The first step is to detect when the "S" key is pressed. (Or is it a button? That makes a difference.)

    Do you know how to do that? Start by creating code that prints "S pressed" when that happens.

    Yes, I know how to create and track button clicks. My main problem is that I can't figure out how to create a list of sprites and change the sprite from the list when clicked.

      Scel
      sudo code:

      var arr = [im1, im2, im3, im4]
      var click = 0
      var current_im = null
      
      func on_but_click():
          click +=1
          if click > arr.size()-1:
              click = 0
          current_im = arr[click]