Search code examples
mit-scratch

How to make a sprite display a variable


I am making an 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 health 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 such as Candy Clicker do this but I don't know how to replicate it. Does anybody know how to do this?


Solution

  • 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.