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!
Offline
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
when gf clicked forever if <(lives) > (0)> Run game scripts... wait until <(Score) > (14)> if <(lives) > (0)> Run game scripts... end end
when gf clicked forever if <(lives) > (0)> show Run game scripts... else hide end
Last edited by ErnieParke (2013-03-15 21:00:06)
Offline
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)
Offline
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 EndYou 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.
Last edited by CAA14 (2013-03-15 23:51:38)
Offline
This is a simple idea for just one script:
when gf clicked forever if <(lives) < (1)> stop all end endYou 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 allHope this helps!
Offline
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!
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-1The 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?
forever showIt means that the enemy will show, FOREVER.
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 hideNow 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 scriptNote that there is a forever block here. But, did you see that a hide block was in there?
Offline