Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Losing Lives
- SpitfireAnimations
-
Scratcher
34 posts
Losing Lives
PLEASE READ!
———————
Take a look inside this project.
Take a look at the Sprite 10 and Sprite 15, and show me how to lose lives.
I would recommend you actually play the game first so you can understand even more clearly what my problem is.
Thanks!
———————
Take a look inside this project.
Take a look at the Sprite 10 and Sprite 15, and show me how to lose lives.
I would recommend you actually play the game first so you can understand even more clearly what my problem is.
Thanks!
- Just_Ciaran
-
Scratcher
100+ posts
Losing Lives
Well my internet is bad so I can't check it but this is the basic code used in most games to lose ‘lives.’ Enemy sprite is replaced with whatever the sprite that if the player touches will lose a life. Lives is a created variable that I assume you have created, otherwise you have the do: when clicked - set Lives to 3(?).
when green flag clicked
forever
if <touching [Enemy Sprite v] ?> then
change [Lives v] by (-1)
end
end
- deck26
-
Scratcher
1000+ posts
Losing Lives
Rather than the wait until lives=0 just check for lives = 0 in the ‘loselife’ receiver. Might be better to check for lives < 1 in case lives get lost quickly and you don't get a chance to spot lives=0 though. Sprite15 otherwise looks OK - naming your sprites is useful by the way, it can help reduce errors and make coding clearer.
In sprite10 you probably want broadcast and wait for ‘loselife’ or the forever loop will re-broadcast and the script may never run to completion. Might also make sense to wait until not touching the fence colour after broadcasting loselife so a single touch doesn't knock off multiple lives.
In sprite10 you probably want broadcast and wait for ‘loselife’ or the forever loop will re-broadcast and the script may never run to completion. Might also make sense to wait until not touching the fence colour after broadcasting loselife so a single touch doesn't knock off multiple lives.
- elcooler
-
Scratcher
24 posts
Losing Lives
Use this script



Put live variable input as you want to the message you can make a sprite that shows when it recieves the game over message.






when green flag clicked
set [Lives] to [3]
forever
if <touching [Evil Sprite] ?> then
change [Lives] by (-1)
if <(Lives) = [0]> then
broadcast [game over] and wait
end
end
end
Put live variable input as you want to the message you can make a sprite that shows when it recieves the game over message.



when I receive [looked reply]
forever
go to [my profile and my projects :v]
end
- Discussion Forums
- » Help with Scripts
-
» Losing Lives