'How to make a sprite display a variable

I am making a Undertale-Based game on Scratch, and I am trying to make a health counter that shows how much health you have. I could always make the variable viewable but I want it to fit in with the game and not stick out like a sore thumb. I've seen other games like Candy Clicker do this but I don't know how they make the sprite display the variable. Does anybody know how?



Solution 1:[1]

To do a sprite counter similar to Candy Clicker, you would need to use clones. You need to create a sprite with costumes for 0-9 numbers. Then you would need to have that sprite clone itself for however many digits you want to display, let's say 3, and then set its costume to the letter number of the variable that the clone's digit corresponds to. I'm not great at explaining stuff like this, so that might have seemed a bit complicated, so the short version is you need to create sprites that display the digits from costumes. I have created a demo at https://scratch.mit.edu/projects/677633446/editor with comments in the code.

Solution 2:[2]

Just put the variable in a "Say Block" and put that in a "Forever Loop".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DT_
Solution 2 Ayushman Das