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

#1 2013-03-15 19:37:54

StarscreamClone
Scratcher
Registered: 2012-05-19
Posts: 1000+

End Game Trouble

Okay, so I'm making a minigame for a collab.  I'm having trouble trying to get it so that when the lives reach 0, everything in the game ends without messing up the rest of the project (there will be a few games in the project).  All the sprites I'm having trouble with either have forever blocks or looping broadcasts.

Any help is appreciated!  Thanks!  big_smile


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i1154.photobucket.com/albums/p522/lizzyhipo/Angelica101-1-1-1.jpg&link2=http://i46.tinypic.com/2elqwdy.png&link3=http://i1273.photobucket.com/albums/y404/Hulydooly/decepticon.jpg&link4=http://i44.tinypic.com/34rvb07.png

Offline

 

#2 2013-03-15 20:58:18

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: End Game Trouble

This really depends on how you built your game. In most cases, using just an if statement around all of your game's scripts should be enough, though sometimes you're going to need several if statements, especially if you're script contains a wait block. Basically, this is what you could do:

when gf clicked
forever
 if <(lives) > (0)>
 Run game scripts...
 end

Another example:

when gf clicked
forever
 if <(lives) > (0)>
 Run game scripts...
 wait until <(Score) > (14)>
  if <(lives) > (0)>
   Run game scripts...
  end
 end

And a third example, just to show a possibility:

when gf clicked
forever
 if <(lives) > (0)>
  show
  Run game scripts...
 else
  hide
 end

Well, I hope that this helps!

With regards,

ErnieParke

Last edited by ErnieParke (2013-03-15 21:00:06)


http://i46.tinypic.com/35ismmc.png

Offline

 

#3 2013-03-15 22:14:17

joshuaho
Scratcher
Registered: 2012-08-20
Posts: 100+

Re: End Game Trouble

ErnieParke wrote:

This really depends on how you built your game. In most cases, using just an if statement around all of your game's scripts should be enough, though sometimes you're going to need several if statements, especially if you're script contains a wait block. Basically, this is what you could do:

when gf clicked
forever
 if <(lives) > (0)>
 Run game scripts...
 end

Another example:

when gf clicked
forever
 if <(lives) > (0)>
 Run game scripts...
 wait until <(Score) > (14)>
  if <(lives) > (0)>
   Run game scripts...
  end
 end

And a third example, just to show a possibility:

when gf clicked
forever
 if <(lives) > (0)>
  show
  Run game scripts...
 else
  hide
 end

Well, I hope that this helps!

With regards,

ErnieParke

You can also use repeat until blocks, so you won't need to drag an extra control block.

Last edited by joshuaho (2013-03-15 22:14:46)


Did you know that you can go to space and see Mars by clicking here?

Offline

 

#4 2013-03-15 23:48:55

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: End Game Trouble

Basically, just make a variable called game over in that weird circle thing, and then put this before all your your playing scripts:

When I receive [play SD v]
Forever
If < not < < [game over v] of [weird circle thing v] > = [yes] > >
Do the forever loops and other stuff...
End
End
You may also have to I sent that if statement in to other parts of the script, depending on how long it is, as I will only check that if statement every time it comes around the loop.

Then you just need to set game over to no when the game starts, and set it to yes when Ives is less than one. I am actually doing that very thing on my current mini game, so I know it works.  wink

Probably wont be on much tomorrow...

Regards,

CAA14

Last edited by CAA14 (2013-03-15 23:51:38)

Offline

 

#5 2013-03-16 03:49:55

newnewfew
Scratcher
Registered: 2013-02-23
Posts: 68

Re: End Game Trouble

This is a simple idea for just one script:

when gf clicked
forever
 if <(lives) < (1)>
  stop all
 end
end
You may want to have the sprites do things so:

when gf clicked
repeat until <(lives) < (1)>
 do the script stuff
end
broadcast [game over]
do my game over stuff
stop all
Hope this helps!


It's contest time!
http://scratch.mit.edu/projects/newnewfew/3218957

Offline

 

#6 2013-03-16 09:59:24

StarscreamClone
Scratcher
Registered: 2012-05-19
Posts: 1000+

Re: End Game Trouble

Thanks guys!  I really appreciate it, and all this should be sufficient!


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i1154.photobucket.com/albums/p522/lizzyhipo/Angelica101-1-1-1.jpg&amp;link2=http://i46.tinypic.com/2elqwdy.png&amp;link3=http://i1273.photobucket.com/albums/y404/Hulydooly/decepticon.jpg&amp;link4=http://i44.tinypic.com/34rvb07.png

Offline

 

#7 2013-04-15 21:20:19

joshuaho
Scratcher
Registered: 2012-08-20
Posts: 100+

Re: End Game Trouble

StarscreamClone wrote:

Okay, so I'm making a minigame for a collab.  I'm having trouble trying to get it so that when the lives reach 0, everything in the game ends without messing up the rest of the project (there will be a few games in the project).  All the sprites I'm having trouble with either have forever blocks or looping broadcasts.

Any help is appreciated!  Thanks!  big_smile

Let us see an example of a game with a enemy and a player.
The enemy has this script:

when gf clicked
forever
show
move (2) steps
if on edge, bounce
if touching[sprite2]
change  [life] by-1


when I receive[gameover]
hide

when I receive [replay]

forever
show
move (2) steps
if on edge, bounce
if touching[sprite2]
change  [life] by-1

The player has this script:
when gf clicked
show
forever
if
distance to (mouse pointer) >10
point towards sprite (mouse pointer)
move (10) steps
if [life=0]
hide
broadcast[gameover]
when I receive[replay]
show
forever
 if
distance to (mouse pointer) >10
point towards sprite (mouse pointer)
move (10) steps
if [life=0]
hide
broadcast[gameover]
Then, you have a replay button come in.
when I receive [game over]
Go to x(0) y(0)
show

when sprite 3 clicked
hide
broadcast[replay]

Ok. Now that we have the player broadcasting game over when the life =0, the enemy is supposed to hide. But did you notice the forever block and the show block in it?
So, if you put this:
forever
show
It means that the enemy will show, FOREVER.
So, even if you put a broadcast message that says game over and a block that tells the enemy to hide when game over message is received, it will not hide, because of the forever block.

So, here is the correct scripting that should have been used for the enemy:
when gf clicked
show
repeat until (life=0)
move (2) steps
if on edge, bounce
if touching[sprite2]
change  [life] by-1
end
hide
When I receive[replay]
show
repeat until (life=0)
move (2) steps
if on edge, bounce
if touching[sprite2]
change  [life] by-1
end
hide
Now let's go back to the player.
when gf clicked
forever 
if
distance to (mouse pointer) >10
point towards sprite (mouse pointer)
move (10) steps
if [life=0]
hide
broadcast[gameover]
Stop script
Note that there is a forever block here. But, did you see that a hide block was in there?
That means that the player will hide. Also, did you see the if? It means that the player will hide ONLY if life=0.
Now, if you had a replay button clicked, the player won't appear a second time. So, that is why you need a stop script. It stops running the script, but will run again when prompted.

I hope this helps!  smile


Did you know that you can go to space and see Mars by clicking here?

Offline

 

Board footer