Help: Using tile graphics to represent health value. How do I make it scalable, as opposed to hardcoding values?

I've been using your example code in a separate project to try and tweak it to my needs and it's working! Based off your example I was also able to make it draw the "empty" hearts as well so that the player always knows what their maximum health is, and it's all scalable!

hearts_test

Now you've essentially solved my problem, which I am grateful for, but if you're able could you offer some more insight into one part of your code that I don't quite understand?

I actually think I grasp the whole modulo function now and how it's determining whether to draw a half or whole heart, but I still don't actually understand how the while loop is working?

while hearts>0 do
	heartString = "{heartString}{embed:heart}"
	hearts--
end

I understand that it's decrementing hearts each loop until it reaches 0, but I'm just not understanding the syntax of how embed works. How is it drawing multiple hearts? Is the value of heartString telling it how many heart tiles to embed? Is it embeding an extra tile every loop until it reaches 0?

I guess just an overhead view of the logic would help, but again, you've already solved my problem so thank you for that!

(Here's my modified project in case anyone wants to check it out)
hearts test.zip (2.7 KB)

4 Likes