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

#1 2010-03-01 12:39:42

shamoon
Scratcher
Registered: 2010-02-28
Posts: 7

how to end a game if the variable value equals zero?

Hey guys,
I made an action fighting game,
I've made a variable which represents the health of a fighter(sprite),
what should i do..so that as soon as the variable becomes zero.the script ends??

Offline

 

#2 2010-03-01 12:43:29

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: how to end a game if the variable value equals zero?

If<(variable) = 0>
|End script
End if

Offline

 

#3 2010-03-01 12:47:14

Wolfie1996
Retired Community Moderator
Registered: 2009-07-08
Posts: 1000+

Re: how to end a game if the variable value equals zero?

How about:

<when green flag clicked>
<forever>
<if><( <{ Variable }> <<> 1 )>
<stop all>
<end>

The reason I used "less than one" not "equals zero" is that Scratch might not detect the exact moment that you get zero, which could mean that you get negative lives. But with my method, it works. Hope this helps  smile


"...Jargon - the practice of never calling a spade a spade, when you might instead call it a manual earth-restructing implement..." - Bill Bryson, Mother Tongue

Offline

 

#4 2010-03-02 14:50:12

Stickman704
Scratcher
Registered: 2009-01-31
Posts: 1000+

Re: how to end a game if the variable value equals zero?

^
and also if you want a "you died" message, then use broadcasts.

[blocks]
<when green flag clicked>
<forever if> <( Health <<>1 )>
<broadcast[You died message
<end>
[/blocks]

And then to all your sprites

[blocks]
<when green flag clicked>
<show>

<when I receive[ You died message
<hide>
[/blocks]

Then create another background called die message. Chuck some "You died" text on it or whatever. (I won't be surprised if you are asleep reading this now  big_smile )

On the background put:

[blocks]
<when green flag clicked>
<switch to background[ Normal background

<when I receive[ You died message
<switch to background[ You died background
[/blocks]

Like that. Quite simple.  smile


Dun dun dun dun dun dun.... dun dun dun dun dun dun...  tongue

Offline

 

Board footer