<solved>hpBar Width = NaN?

I have an hp bar, which is supposed to appear over the head of every character. But, however, when I actually modify its width to match the percentage of the max hp that the character has left, the Width gets set to NaN. This occurs after the hpBar Width is saved to an object variable called width, and instantly after the variable widthSaved becomes True, meaning that it must be caused by the event that modifies the Width to be 100/100*hpBar.width, so basically, the event that actually doesn’t change the Width at all yet somehow changes it. And according to a helpful text object I’ve got that displays hpBar.width, toString(hpBar.Width()), toString(hpBar.Height()), (this is simplified slightly; shown in below images) the Width is set to NaN. What does NaN even mean and why is the Width set to that, rather than, its regular Width, which is what 1 * it’s regular width should equal?




(16x2 red bars should be displayed over the heads of the characters. They’re displayed as actual Roman characters because I’m still just working on mechanics.)

Not A Number

Do you understand you are changing HP bar width to its width as multiplier?

Like your HP bar is 20 pixels wide
Now you multiply it by 5 so you get 100 but at the same time you are multiplying it now by 100 so you get 500
And now you are multiplying it by 2500 and so go on
I wonder why you did not get infinity

Formula is

Bar width / Max HP * Current HP

BUT Bar width cannot be Bar.Width()
It needs to be static number which cannot be changed
Which should be initial width of your bar
So if your bar is 20 pixels wide you should use

20 / Max HP * Current HP

But for sure do not use width expression cause you are making a loop

hpBar.width is not toString(hpBar.Width()). This may be a bit confusing, admittedly. And the reason for this is the exact problem you are suggesting. hpBar.width is assigned only once, upon the creation of the hpBar object, with a trigger once while true condition before it, which means that it should (though, may not be) a static number that isn’t changed. My formula, if you would take a peek at the events screenshot i posted, is`

(This is how you do this, right?)

character.hp.current/character.hp.max*hpBar width upon creation.

`Besides my little modification of saving the width upon creation to a variable, that’s how the wizard-dude did it in the tutorial video on just this. The reason I made that modification was that I want everything graphics-related to be as versatile as possible because my graphics, which aren’t even a work in progress yet, are extremely liable to change.

I took
And i get what you are trying to say

For me only thing wrong in your screenshots is the fact height is displayed properly but width is not

Which i have no idea why it happens

What if I swapped out the whole variable thing for toString(hpBack.Width()) (theoretical object), with hpBack being created before hpBar, as to be behind it, and with it always being at the max width?

Theoretically, it would work, and it would add a bit of style.

Okay, now it shows up, and width is good. But the width of hpBar doesn’t change according to Bob’s hp. The only condition for this is that the hpBar is stuck to a character (stuck, from sticker behavior), which is just to pick the character that the variables are coming from. It doesn’t even register Bob’s hp, however, because when I changed Bob’s hp to 50, it still shows up as 100 on the bar.
The new events:




I’m about this close to just putting in UI for each party-member; NPC hp isn’t supposed to be visible anyways (though it’s still supposed to be there). Or maybe just feature an hp tooltip whenever the mouse hovers over a party-member.

I am not sure
Sticker is doing what it should do like tells game that one object is linked to another

This is how i link objects
Try to link in the same way your bars instead of using sticker

I got it; instead of using your equation exactly, I modified the width being used to the character’s width divided by 1.5, and I added parentheses, which I was a little worried about because I wasn’t certain I had understood the order of operations being used there, but from what I can tell, it all worked perfectly well, this time, because whenever I hit shift and click Bob, he loses 10 hp.




Poor Bob. Getting picked on all the time for the sake of science. If I didn’t have such a good reason to pick on him, I’d feel sorry for the little dude.

It even still works if I modify the characters’ sizes:

Not gonna lie i am not being able to even grasp why its happening

For me you are doing something to width in events which you did not show

Because how otherwise explain height working perfectly fine?