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

#1 2011-10-08 20:41:25

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

Health going past 0 D=

So, im making  a sort of mini Halloween game. Mainly because I cant think of a better one.

Now

Theres special moves if you hit a special key, that will take more health of the enemy than the normal attack.

Say the enemy is on 2 health, and you use a attack that takes off -3 health, that equals -1

What I need it to get it to do is that it will not go past 0.

Is that possible?

Offline

 

#2 2011-10-08 20:46:35

Zparx
Scratcher
Registered: 2011-03-23
Posts: 500+

Re: Health going past 0 D=

Babado wrote:

So, im making  a sort of mini Halloween game. Mainly because I cant think of a better one.

Now

Theres special moves if you hit a special key, that will take more health of the enemy than the normal attack.

Say the enemy is on 2 health, and you use a attack that takes off -3 health, that equals -1

What I need it to get it to do is that it will not go past 0.

Is that possible?

YES! use this code!
lets say your variable for the enemy's health is "enemy health" for this example:

{when green flag clicked}
    {forever}
    {if <enemy health = 0 or enemy heath < 0}
    {set enemy health to 0}
    {(then for right here, you could put a script for the enemy to die. Such as "hide")


That code has been tested by me and you can see alot of similar instances of this in my games, so I know it works! Happy scratching (:

Last edited by Zparx (2011-10-08 20:47:48)


http://images3.wikia.nocookie.net/__cb20101119183412/halo/images/4/43/Hero2.png
^ My rank on Halo: Reach :3

Offline

 

#3 2011-10-08 21:03:53

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

Re: Health going past 0 D=

May I ask what "< 0 " does?

Offline

 

#4 2011-10-08 21:49:47

Zparx
Scratcher
Registered: 2011-03-23
Posts: 500+

Re: Health going past 0 D=

Babado wrote:

May I ask what "< 0 " does?

Well the symbol "<" means "less than" in math terms. so the code put simply is like this "If enemy health is less than 0". and after that you have your code "set enemy health to 0". So "If enemy health equals 0 or enemy health is less than 0, set enemy health to 0" This assures that the enemy's health will always go to 0 when you kill it. Do you understand it better now? (:


http://images3.wikia.nocookie.net/__cb20101119183412/halo/images/4/43/Hero2.png
^ My rank on Halo: Reach :3

Offline

 

#5 2011-10-08 21:50:51

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Health going past 0 D=

Less than, so if the health is less than ( < ) 0, then your character dies, or you can set it to 1, so if it's 0 or less they will die. ( Which I suggest doing. )

[img]http://share.wiredtron.com/files/238/Scratch Script/lessThan0.gif[/img]

Hmm, for some reason the image isn't showing, click this link to see it: http://share.wiredtron.com/files/238/Sc … sThan0.gif

Last edited by Magnie (2011-10-08 21:53:58)

Offline

 

Board footer