I want to have a number that represents the health of my enemies

i’m just experimenting with simple games, and i want to add a number to represent the health of my enemies, how do you make a number that sticks to every enemy clone?


Object variables, I think. I’m using a similar thingy in my game

Normal game rules like when game starts counts for clones as well, so yeah. And the variable saves for each individual clones


i know these, but i want to show the number for health on the enemy clone


Not sure what you mean, but you could do
“set text >> hp”


have a string with all the enemy hitpoints (make sure to make each hitpoint part the same length) then in a new object read that string and set text accordingly
whenever an enemy loses a hitpoint, manipulate the string to update that change:

set hpString to 002|001

// clones in one object 
set text to characters in hpString between self(clone index - 1) * 4 and (self(clone index - 1) * 4) + 3

// enemy hitpoint updating
when I lose a hitpoint // rule where enemy loses a hitpoint
increase self hitpoints by -1
if self hitpoints < 10
set hpString to ((characters in hpString between 0 and (self clone index - 1) * 4 + 1) + 0) + self hitpoints + (characters in hpString between ((self clone index - 1) * 4 + 3 and length(hpString)

the lowest may have an error in it
also it’s kind of complex so let me know if you want me to make a sample project with it


i would like a sample project :DD.


Here’s a simple example that just passes data between objects

The key to this is the objects & texts have to be created in an alternating sequence. E.g., object(0), text(0), object(1), text(1), etc

Then a global variable can be used to pass data between each object/text pair. Since the objects & texts alternate, each object can set the global variable to its data, and the next text will read the data from the variable. The next object changes the data, and the sequence continues.

The stage objects have to be in this order

I created the clones like this but it doesn’t have to be done this way. The end result just has to be an alternating clone creation sequence as a mentioned above

It’s similar for both object (circles) and the text, but I used different custom abilities to so the circles & text could be initialized differently. Check the example project.

Then the circles simply do this to pass data

While the texts simply read it. Note: This takes two rules so the code in each happens every frame.


Ok so a few questions. Where should the health be shown (at the top, above the enemy. Etc.)? Do you want the health as text or as a health bar?


i would make it as texts, and it is on the centre of the enemy


thanks , that explanation was simple and understandable :))


I thought this was an interesting use case, so I made another example with a bar instead of text. Posting just for future use if people are searching with a similar question…

The text is now a square that does this to create the health bar

Check the project for the full formula to vary the color according to the health


Solved in post #8