 Hello world, it's The Serving Scratchy here, teacher-serviced programmer and on this channel I help curious owners just like you along on your learning journey. Welcome to the scratch installment of our spelling game here where we're going to integrate our spelling little program that we created in Scratch and we're gonna integrate it with an existing game. The idea is that each word a user spells correctly, they will get a life for the game. It's basically like a token. And if you take this concept, you can apply it to any other game that uses lives out there in Scratch. It's just a way to earn lives as opposed to getting them for free. If you're not too sure on how this works, maybe check out the start of the series, look at the cards in the top right hand corner or check out the starter projects down in the description. Okay, let's go check out the game that we're gonna integrate this with, just quickly. Okay, I've got this little space shooter game called Scratch Control Blocks. It's from a previous video. Go check out the card in the top right hand corner to suss it out. Or a link below is in the description for it. I've added a couple more features to this game. So it's just some sound effects and a score here. So all it's pretty simple game. It's gonna click the green flag here. And all we need to do is shoot these spaceships and avoid the asteroids. So let's go ahead and do that. And avoid the asteroids as they come hurtling down to us. And if they hit us, then the game is over. Now, the idea is instead of the game being directly over, we will lose lives instead. So we're gonna integrate the spelling game with this space shooter game that we have here. Okay, I'm back over here in the spelling game. Again, there's a link below in the description to work along with me if you don't have a copy. We're gonna be using the backpack. And what we're gonna go ahead and do, and you can see I've already had a little go at doing this. I'm gonna delete those. We're going to get these two sprites and we're going to put them in the backpack. Okay, the backpack means that we can transport some code or some assets between projects. So now we've got dot and the word data in our backpack and we can go across to the scratch control box. Now we're back over here in the scratch control box shooter game. I'll open up the backpack. You see we've got dot and the word data here. And all we need to do is just drag them back over into the sprite pane and we will get both of those sprites for this game. So that's really neat. We've got all that logic from our game already in here. Okay, so I'm just gonna close the backpack there and we've got dot on the screen. We don't really need dot on the screen. I'm just gonna hide a dot and word data is an empty sprite. Very first thing I'm gonna do is go back through each of the existing sprites in our scratch control box game here. And whenever I see a, when the green flag is clicked hat block, I'm instead going to use an event. And I'm going to use an event that is going to be called start game. And wherever I see that hat block, I'm just going to move it across to start game. Cause currently the game starts on a green flag press, but we don't want it to happen. We want the spelling to start on a green flag press. So that's what we're gonna do doing that. Once in the laser, we don't need to worry about it for the beam. We've got it here in the spaceship where we need to do it as well. So instead of when the green flag is clicked when we receive start game, we've also got it over here in the asteroid sprite. And we're going to leave it for the star sprite because the star just creates the background and that's quite a nice effect. So we're just going to leave that as it is. The last sprite that we'll need to do it to is on the stage and I will drag that out and put that forever loop in a start game. I'm actually going to leave this as when the green flag is clicked. So we can switch to the backdrop of game because there is a thumbnail for this project too. Okay. I'm just going to press the stop sign there and the green flag and we can see our stars build in and the game, we can't play it yet. So that's what we're looking for. Now we need to start our spelling game and to do that we're going to jump inside word data. Okay. So I've just got a little comment here and this is what we're going to be following to execute this to make this all functioning. So back in our spelling game we've got this variable called correct which is a count of the number of correct words that we spell. Now instead of having correct I'm just going to rename this and we're going to make this live because every word that we spell correctly well we want that to be alive. So let's just call it lives instead. We're going to initiate lives here when the green flag is clicked and we're going to set that to zero. Okay. We want to show the lines list. So let's go down into our list blocks here and we're going to show the list of lines. Let's just tick it so we can see it and I'm going to make it a little bit bigger here and this is so the user can see what are the current lines that we're going to be using. Just going to go back into dot and hide our results there. Okay. Now we're back in word data. We want to prompt the user and ask them if they want to change the list. It's more just a bit of feedback. So to do that we use the ask and wait block. And what we're going to do is ask them this. We're going to ask them if they want to change the lines. We're going to get them to type in to continue which in means no. But if they want to change the lines they're going to right click the lines list and import those lines. Okay. And we want to do this until the answer that we get is equal to N but not just N because we can't proceed if we've got an empty list here. We also want to make sure that the answer is equal to N and that our length of lines is greater than zero. Now this is going to be completely foolproof because if we don't have the correct format for our lines here then this will probably break as well. So I'm aware of that but we're just going to work on the assumption that the person knows the format of the lines. And then we can connect this just below the show list line because after we're happy with the lines we want to extract the words and sentences from those lines. Let's just click the green flag and test it out. So we've got the green flag now. Do you want to import the lines? If we type N here it won't go away because lines is currently equal to zero. Okay. So if I go ahead and import those words now I'm going to open them and you'll see that our lines have been populated. And what I'm going to do is I'll just delete a lot of them just so we don't have to go through the whole game for our testing purposes. And now I'm going to type N because we don't want to change the lines that we've got and let's do that. Great. So we just test and look at our sentences and words there. We can see that we've extracted those lines that we just imported in. So that's what we want. After we've done that let's hide the list of lines and then let's broadcast not start game but we're going to start the spelling side of this. So let's start the spelling game. Okay. Now we're going to work in the dots bright. Instead of the when the green flag is clicked hat block we're going to be working with an event hat block and we want to be working with the start spelling game event. Let's go grab the set lives and let's put all of it there in the start spelling game. We want to, we'll hide the results directly when we click the green flag. So that way they are never visible. In fact, we don't ever want to see the results in this game. So I'm just going to remove that. Okay. When we start the spelling game we want to make sure that we show dot on the screen. And once we've played the spelling game we need to broadcast a message and that message would be start game. And then when we receive start game we're going to hide dot from the screen again. Remember that we just set up the start game event for the rest of our blocks or the rest of our sprites here in the sprite pane. And when dot receives start game we're just going to hide dot and hide this spelling game. I'm just going to give this a little test out to see how we went. Okay. So I'm just going to click the green flag here. We can still see our lines on the screen. Do we wish to change them? Nope. We're going to leave them as they are. Okay. Should she try to make a dash for the car? Dash. Great. So we've got the spelling game working here. I can see the laser still on the screen. So we may need to hide the laser on a green flag press or click. Let's type in dash. And then I'm expecting our game to start. Cool. So our game started. I noticed a couple of things here. We don't have any lives up here in the screen. So we'll need to go ahead and change that. So on the whole it's working pretty well. So back here in the when I received start game hat block let's show the variable lives just so we can see it. And on the green flag click let's make sure that we hide that variable. We could do the same thing with our score because we don't need to see the score until we start the game. Let's go back into our laser sprite. And when we receive start game let's make sure that we show it. And on a green flag click we will hide that laser. So you can see I just put in another line here for outlines list. What I'm going to do now is fast forward this just so you can see that we're going to get a couple of lives when we spell these both correctly. So you can see we've now got two lives in our game. And so that's going pretty well. But there's going to be another bug that we haven't finished yet because as soon as an asteroid hits us the game is over. So let's go and fix that bug. So currently our game ends when our asteroid is touching the laser. So instead of just executing the sets of instructions we're going to use an if and else block. We're going to check to see if our lives are greater than one. If they are we're going to lose a life instead. So we need to change our lives variable by negative one. And then we still want to clean up after ourselves. We want to delete this clone else. Well that means our lives are going to be less than one and we want to end the game. So let's just whack that code block in a side of that if block. Now you can see this is getting a little bit unwieldy and I would put all these in custom blocks but I'm not going to worry about that for the moment. Let's go test this out. Okay here we are in the second word bath. I'm going to spell it correctly. Boom and our game is about to start. Okay so you can see our lives are currently equal to two. We're shooting down. Ooh okay and I just lost a life there. We didn't hear that sound. So we will probably want to move that sound into the other spot of the if block as well but we should hear it right now. There we go. So that is working just as it should. Let's get that crash sound and let's play it when we lose a life as well. Okay I reckon we're going to leave this game as it is. There is one known bug that we're not going to get to in this video. I'm going to leave that for a challenge for you to sort out. And that bug is if you don't spell any words correctly you are still given one life in this game. So I'll set that for you as a challenge to see if you can make this game nice and sturdy and robust. But this tutorial has all been about how we can integrate our spelling game to create lives for any other game on scratch that also has lives. When I'm changing between states and games I usually love to use a state machine. Go check the card in the top right hand corner which is a video on a simple state machine that you can use in scratch. It's really really handy to use in your game development. So highly recommend you check that out as well. But I hope you enjoyed this series and I hope you're ready to get busy with Python if you haven't already. So come and join me in the next tutorial where we start to transition from scratch to Python.