0 votes
by (140 points)

I want a system in my game that shows a heart for each health point the player character has. To do this I made a for loop:

<<for _h to 0; _h < $health; _h++>><<print $heart>><</for>>

However, when I run the game the health bar doesn't show, like so. Is my for loop wrong?

1 Answer

+1 vote
by (159k points)

You don't state what the current values of the $health and $heart variables are, but assuming that:
a. The $health variables equals an integer greater than zero 0.
b. The $heart variable contains a value that can be printed.

... then the syntax of your <<for>> macro is correct.

note: if the $heart contains a simple String value then you don't need to use the <<print>> macro, you could use a Naked Variable instead.

by (140 points)
Oh yeah, should have mentioned what they are! $health is set to 3 and $heart is &hearts;. Thank you!
by (23.6k points)

Try it like this:

<<for _h to 0; _h < $health; _h++>>&hearts;<</for>>

This works perfectly fine for me too though:

<<set $health to 3>>
<<set $heart to "&hearts;">>

<<for _h to 0; _h < $health; _h++>><<print $heart>><</for>>

 

by (140 points)
That worked, thank you!! (I guess it prefers &hearts; (typed) to alt + 3?)
...