Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Health bar
- Red_Falconboy
- Scratcher
47 posts
Health bar
I am looking for how to use some code for my health bar. It is a green yellow red bar with three health settings and when it reaches zero it disappears. The problem is I don't know how to code it and I don't want to use variables. Here is the current code:
when green flag clickedAlso, it doesn't change the costume number.
go to x: (50) y: (0)
when I receive [message]
switch costume to ((backdrop #) - (1))
Last edited by Red_Falconboy (Dec. 2, 2021 21:41:59)
when green flag clicked
say [Hi!] for (2) secs
say [Good Morning/ Afternoon/ Evening!] for (2) secs
- 1-o-v-e
- Scratcher
100+ posts
Health bar
So to recap, you're looking for:
three health settings
disappears when it reaches zero.
you don't want to use variables.
it doesn't change the costume number
So, your first two points are relatively easy to pull off on their own, but this would be a bit more difficult without variables. There are other solutions, however, your last note makes this even harder.
If you're not looking to use complicated code, you probably should just make a new sprite, so it can change costume number, but if that's not an option, you may want to consider putting the health bar costumes in the backdrop or using cloning in the sprite. Cloning is a great solution and the abstraction definitely can help compact your work, but it kind of only works best with variables.
If you figure out which one of these you'd like to use (or if you don't like any of these options, which is fine too) just let me know and I'll happily try to help you figure it out from there!
three health settings
disappears when it reaches zero.
you don't want to use variables.
it doesn't change the costume number
So, your first two points are relatively easy to pull off on their own, but this would be a bit more difficult without variables. There are other solutions, however, your last note makes this even harder.
If you're not looking to use complicated code, you probably should just make a new sprite, so it can change costume number, but if that's not an option, you may want to consider putting the health bar costumes in the backdrop or using cloning in the sprite. Cloning is a great solution and the abstraction definitely can help compact your work, but it kind of only works best with variables.
If you figure out which one of these you'd like to use (or if you don't like any of these options, which is fine too) just let me know and I'll happily try to help you figure it out from there!
–––––––
⧈ ⟦ 1ove or Marsh // she • her • hers // artist • animator ⟧ ⧈
Hey there! You can call me Marsh (or 1ove).
Although I'm relatively new to the forums, I've been on scratch for 5+ years. If you've been around for a while, feel free to pop by my profile—I love re-finding some fellow people from 2.0!
- Red_Falconboy
- Scratcher
47 posts
Health bar
So to recap, you're looking for:
three health settings
disappears when it reaches zero.
you don't want to use variables.
it doesn't change the costume number
So, your first two points are relatively easy to pull off on their own, but this would be a bit more difficult without variables. There are other solutions, however, your last note makes this even harder.
If you're not looking to use complicated code, you probably should just make a new sprite, so it can change costume number, but if that's not an option, you may want to consider putting the health bar costumes in the backdrop or using cloning in the sprite. Cloning is a great solution and the abstraction definitely can help compact your work, but it kind of only works best with variables.
If you figure out which one of these you'd like to use (or if you don't like any of these options, which is fine too) just let me know and I'll happily try to help you figure it out from there!
It's fine if the costume number changes. I was saying that it is not changing the costume number
when green flag clicked
say [Hi!] for (2) secs
say [Good Morning/ Afternoon/ Evening!] for (2) secs
- 1-o-v-e
- Scratcher
100+ posts
Health bar
Oh, that's an easy fix! You have to take out the block that looks like this:
The reason your previous one didn't work was because the code you wrote was made to change the costume of the backdrop, not the costumes of sprite itself. It's an easy mistake to make, since the two blocks look so similar- I've made the same mistake myself many times haha-
Anyways, I hope this helps, and sorry for misinterpreting earlier!
(backdrop #)and replace it with this:
(costume #)(you can find this replacement block in the “looks” section of your sprite.)
The reason your previous one didn't work was because the code you wrote was made to change the costume of the backdrop, not the costumes of sprite itself. It's an easy mistake to make, since the two blocks look so similar- I've made the same mistake myself many times haha-
Anyways, I hope this helps, and sorry for misinterpreting earlier!
–––––––
⧈ ⟦ 1ove or Marsh // she • her • hers // artist • animator ⟧ ⧈
Hey there! You can call me Marsh (or 1ove).
Although I'm relatively new to the forums, I've been on scratch for 5+ years. If you've been around for a while, feel free to pop by my profile—I love re-finding some fellow people from 2.0!
- MrNanners
- Scratcher
100+ posts
Health bar
I gotch you fam I am looking for how to use some code for my health bar. It is a green yellow red bar with three health settings and when it reaches zero it disappears. The problem is I don't know how to code it and I don't want to use variables. Here is the current code:etcAlso, it doesn't change the costume number.
when I receive [update_healthbar v]WHAT THIS DOES:
clear // it's "Erase all" in Scratch 3.0 blocks
set pen size to ((size) / (25))
pen up
change y by (((b) * (0.65)) * ((size) / (100)))
change x by (((a) * (-0.5)) * ((size) / (100)))
set pen color to [#ff0000]
pen down
change x by ((a) * ((size) / (100)))
pen up
change x by ((-a) * ((size) / (100)))
set pen color to [#3fff00]
if <((volume) / (100)) < [0.67]> then
set pen color to [#ffff00]
end
if <((volume) / (100)) < [0.34]> then
set pen color to [#ff0000]
end
pen down
change x by (((a) * ((volume) / (100))) * ((size) / (100)))
pen up
change y by (((b) * (-0.65)) * ((size) / (100)))
change x by (((a) * ((0.5) - ((volume) / (100)))) * ((size) / (100)))
if <not<(volume) > (0) >> then
clear // it's "Erase all" in Scratch 3.0 blocks
end
it creates a healthbar over the sprite with the size of the healthbar fluctuating with the costume and size of the sprite, using volume as the health. It will erase itself after health drops below zero
NOTE:
-“a” is NOT a variable, as you specifically requested no variables. It is the WIDTH of the costume. Since you do not want to use variables, you have to input this manually. You find the WIDTH of your costume by going to costumes, finding where it displays a mini-version of your costume, looking under the costume name at the WIDTH x LENGTH numbers, then inputting the right one.
-“b” is NOT a variable, as you specifically requested no variables. It is the LENGTH of the costume. Since you do not want to use variables, you have to input this manually. You find the LENGTH of your costume by going to costumes, finding where it displays a mini-version of your costume, looking under the costume name at the WIDTH x LENGTH numbers, then inputting the right one.
-this will not work with clones since the VOLUME is the same for BOTH clones and the original sprite.
Hope this helps
Last edited by MrNanners (Dec. 3, 2021 01:19:48)
That's about it, see yah.
My best and most helpful projects:
Savable Games Engine | Plants Vs. Zombies | Competitive Clicker Game
As a kid, John Lennon, member of the most successful band in history, the Beatles, said, “When I grow up, I want to be happy.” The teachers around him said that he didn't understand the question, but young John said that {the teachers} didn't understand life.
- Discussion Forums
- » Help with Scripts
- » Health bar