This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-07-21 20:36:41

DewleafWolf
Scratcher
Registered: 2011-01-13
Posts: 100+

How do you make an enemy disappear after hitting 0 health?

Okay, so both my brother and I are having this problem on our Scratch game projects. When the hero sprite attacks an enemy, a variable called Health (visible on the screen) depletes with each hit. The problem: when Health reaches 0, it continues to go into negative numbers...
I've tried:

If [ Health = 0 ]
((hide/change costume/etc.))

If [ Health < 0 ]
((hide/change costume/etc.))

No matter what I do with the Health variable, I can't get it to stop. I have about 3 Scratch projects with a Health, hunger or thirst bar with this same problem. So, how do you fix it?

Offline

 

#2 2011-07-21 20:44:26

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: How do you make an enemy disappear after hitting 0 health?

Checking if health is less than 0 (or more preferably, 1) should work. Does your script look something like this? (Possibly with other things in there too, but I don't know what the rest of your scripts look like.

Code:

When green flag clicked
forever
    if <health < 1>
        hide

http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#3 2011-07-21 22:55:21

DewleafWolf
Scratcher
Registered: 2011-01-13
Posts: 100+

Re: How do you make an enemy disappear after hitting 0 health?

It looks like changing "if" to "forever if" made it work! Thanks.

Offline

 

#4 2011-07-21 23:25:56

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: How do you make an enemy disappear after hitting 0 health?

DewleafWolf wrote:

It looks like changing "if" to "forever if" made it work! Thanks.

That's because "Forever If" constantly checks whether something is true or not, while a plain "if" block checks it only in the moment you run it.  wink


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#5 2011-07-22 15:47:22

DewleafWolf
Scratcher
Registered: 2011-01-13
Posts: 100+

Re: How do you make an enemy disappear after hitting 0 health?

Ah, okay, that makes sense!  smile  I'm still learning most of the blocks' functions, so that helps.

Offline

 

Board footer