How do I make a variable that's an integer?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JasperC

I’m a total noob, so sorry if this is impossible or super basic. I’m trying to make a game where you have a limited number of jumps, I want to show the number of jumps left on the screen. To do this, my idea is to have a bunch of sprites with numbers written on them, with the lowest at the bottom, and the highest at the top. So when you jump, the highest number disappears, revealing the number that’s smaller by one. I want to do this by having the sprites be named the number they are, and then making the sprite with the name of the number_of_jumps_left variable turn invisible. How can I make an integer a variable, so I can do this? If this is impossible, what’s a better way to implement this mechanic?

Here’s some rough code of what I’m trying to do.

var number_of_jumps_left = 10

func _physics_process(delta) -> void:
      if Input.is_action_just_pressed("jump"):
            number_of_jumps_left.visible = false
            number_of_jumps_left -= 1
:bust_in_silhouette: Reply From: Inces

I don’t entirely understand this reasoning.
If You plan to have images of numbers named after those numbers - it will be easier to translate your integer variable to string image path, like this :

number_of_jumps_left -= 1
TextSprite.texture = load("res://numbers/" + str(number_of_jumps_left) + ".png")

TextSprite is exxample name of your Sprite that will change textures
example folder to keep images is “numbers”, and images should be named “1” “2” “3” and so on

Thank you! Finally got this stupid thing working.

JasperC | 2022-04-27 02:01