need help with the math in a rule for a health sprite
Hi
I have ten sprites of a green sphere that represents a players health. Frame 0 100% of sphere visible, frame 10 100% of the sphere in invisible, Frame 5 the top half of the sphere is cut off and so on.
So say when 20% of a players health is gone I want to display frame1
when 30% of a players health is gone I want to display frame 2
i tried a rule with
game.health = game.health*1
Change image to frame 1
worked fine but then I struggled
went
game.health is less than game.health*.8
change image to frame 2
and so on down to 0 but it never changes from the first image.
Anyone know what I am doing wrong?
I have ten sprites of a green sphere that represents a players health. Frame 0 100% of sphere visible, frame 10 100% of the sphere in invisible, Frame 5 the top half of the sphere is cut off and so on.
So say when 20% of a players health is gone I want to display frame1
when 30% of a players health is gone I want to display frame 2
i tried a rule with
game.health = game.health*1
Change image to frame 1
worked fine but then I struggled
went
game.health is less than game.health*.8
change image to frame 2
and so on down to 0 but it never changes from the first image.
Anyone know what I am doing wrong?
Best Answers
-
tatiang Posts: 11,949
Game.health will never equal game.health*.8 (unless game.health is zero). This is like writing an equation x=x*.8
Attributes always contain the current value of the attribute. So as game.health changes, you can't compare it to its former value. You need to use two attributes for this.
You need a game.maxhealth value that you use to compare (e.g. game.health<game.maxhealth*.8). You can either set game.maxhealth to some number before the game starts or you can use a change attribute behavior to set game.maxhealth to game.health when the game begins.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
-
tatiang Posts: 11,949
yes thanks that makes sense. Do you know what I would use if I want a particular frame to display for the range of say game.health Level*.61 to game Level*.8?
Unless you want to work with complex math formulas, you're best off doing:
When [ALL conditions] attribute game.health>=game.Level*.61 [AND] game.health<=game.Level*.8 --> [...]New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
Does anyone know what I would use if I want a particular frame to display for the range of say game.health Level*.61 to game Level*.8?
I have an 8 frame sprite that I want to change as the value of an attribute increase or decreases
What would the rule look like?
I"ve tried
first rule
game.health=game.health level
change image frame 0
works
then
game.health < or = game.health level*.81
change image frame 1
works
then
game.health < or = random(game health level*.6,game.health level*.8)
change image frame 2
doesn't change, stays on frame1
thanks for getting back to me. I could but I am using this for an RPG styled health sphere where the two variable increase as the player levels up. I was thinking I'd like to use percentage ranges for the images so I could accomodate these level up increases.
so at 100% health frame 0
85% health to 99% frame 1
65% health to 84% frame 2
and so on
I chose to use font based images, but you could just as easily substitute your own "1.png" "2.png" etc. images for your health meter.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User