Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to stop lives going into minus
- blackswan2428
-
Scratcher
70 posts
How to stop lives going into minus
How do you stop lives going into minus? I've tried everything I could.
- blackswan2428
-
Scratcher
70 posts
How to stop lives going into minus
And how do I make a sprite dash?
- Despicable_Dad
-
Scratcher
500+ posts
How to stop lives going into minus
For your first question, here's how I do it…though I'm very old school and probably don't take as much advantage of Scratch features as I should.
when green flag clicked
forever
say [Press SPACE to start]
wait until <key [space v] pressed?>
say []
set [lives v] to [3]
repeat until <(lives) < [1]>
repeat until <touching [enemy bullet v] ?>
game mechanics
end
change [lives v] by (-1)
end
game over
end
Last edited by Despicable_Dad (Nov. 1, 2017 09:51:31)
- kabobbob
-
Scratcher
46 posts
How to stop lives going into minus
Here's something that you could try for sprinting.
Of course, speed would be how fast your character goes normaly. The “left arrow” should also be right arrow, but the product would be inverse (speed*-2) The 2 can also be changed. As well, im interested to see this project. Could you please quote this post with the link to the project?
... :: events
if <<key [left arrow v] pressed?> and <key [s v] pressed?>> then
move (((speed) * (2))) steps
end
Of course, speed would be how fast your character goes normaly. The “left arrow” should also be right arrow, but the product would be inverse (speed*-2) The 2 can also be changed. As well, im interested to see this project. Could you please quote this post with the link to the project?
- RokCoder
-
Scratcher
1000+ posts
How to stop lives going into minus
And how do I make a sprite dash?
For this, add a link to a project where you've tried to do this and explain exactly what it is that you're trying to achieve. Sounds like you just need to increase the movement velocity maybe while a key is being pressed but it would be easier to help if you show what you've already tried and make it clear what you're trying to achieve.
- nathanpig
-
Scratcher
61 posts
How to stop lives going into minus
And how do I make a sprite dash?
Simple, just add a variable for speed, then make a script that sets the speed to a dashing speed when a requirement is met.
when green flag clicked
forever
if <key [space v] pressed?> then
set [speed v] to [3]
else
set [speed v] to [1]
end
end
Then make sure that the blocks your using for movement are using this variable.
when green flag clicked
forever
if <key [d v] pressed?> then
change x by (speed)
end
if <key [a v] pressed> then
change x by ((speed) * (-1))
end
end
- nathanpig
-
Scratcher
61 posts
How to stop lives going into minus
How do you stop lives going into minus? I've tried everything I could.
For this, just use if and and blocks.
when green flag clicked
set [lives v] to [3]
forever
if <<touching [enemy v] ?> and <[0] < (lives)>> then
change [lives v] by (-1)
end
if <(lives) < [1]> then
insert game over script here
end
end
- NpChecker
-
Scratcher
100+ posts
How to stop lives going into minus
An example:
when @greenFlag clicked
forever
if <(Lives) = [0]> then
stop [all v]
end
end
- deck26
-
Scratcher
1000+ posts
How to stop lives going into minus
An example:Much better to put the check in the code that actually changes lives. If you do so in multiple places try using a broadcast so a single script can handle changes to the lives variable.when @greenFlag clicked
forever
if <(Lives) = [0]> then
stop [all v]
end
end
Running a forever loop to check lives 30 times a second or so is not efficient.
- blackswan2428
-
Scratcher
70 posts
How to stop lives going into minus
For some reason everything stopped except the spite that you can control why is that?
AND THANKS FOR ALL THE HELP EVERYONE YOU HAVE BEEN SUCH A HELP
AND THANKS FOR ALL THE HELP EVERYONE YOU HAVE BEEN SUCH A HELP
Last edited by blackswan2428 (Nov. 3, 2017 00:14:10)
- blackswan2428
-
Scratcher
70 posts
How to stop lives going into minus
And can you make the coding for the dashing is a bit simpler thanks
- GamesTV
-
Scratcher
50 posts
How to stop lives going into minus
For the no negative lives thing, Simply code this:
If lives equals zero
(Stop script that has the thing where if you get hit by an enemy or whatever you lose a life)
Switch backdrop to game over (Or whatever your game over screen is named)
Stop all
(50th post btw! *Silent dance*)
If lives equals zero
(Stop script that has the thing where if you get hit by an enemy or whatever you lose a life)
Switch backdrop to game over (Or whatever your game over screen is named)
Stop all
(50th post btw! *Silent dance*)
Last edited by GamesTV (Nov. 3, 2017 03:33:18)
- Yemi349
-
Scratcher
2 posts
How to stop lives going into minus
I figured it out if you want to reset your game after they die here's how
if <(lives) = [0]> then
reset
end
define reset
set [lives] to [5]
go to x: (0) y: (0)
Last edited by Yemi349 (Nov. 5, 2022 16:15:34)
- Yemi349
-
Scratcher
2 posts
How to stop lives going into minus
works for me
the block pictures haven't been updated for scratch 3.0
the block pictures haven't been updated for scratch 3.0
Last edited by Yemi349 (Nov. 5, 2022 16:19:20)
- bsteichman
-
Scratcher
500+ posts
How to stop lives going into minus
how about instead of:
change [lives v] by (-1)you can do
change [lives v] by ((-1) * <(lives) > (0)>)
Last edited by bsteichman (Nov. 5, 2022 18:13:20)
- MC_Hero09
-
Scratcher
89 posts
How to stop lives going into minus
Or a simple way
when green flag clicked
set [ lives] to [3]
forever
repeat until <[lives] = [0]>
if <touching [ enemy] ?> then
change [ lives] by (-1)
end
end
broadcast [ GameOver]
end
Last edited by MC_Hero09 (Nov. 5, 2022 18:27:11)
- Discussion Forums
- » Help with Scripts
-
» How to stop lives going into minus