‫Hey, welcome back.
‫In this video, we're going to work on a widget for displaying the win lose condition.
‫So let's jump right in.
‫Now we have our widget, we start game widget.
‫Let's open that and we'll see that we have this get ready text.
‫And in the event graph, we're setting this in event tech.
‫Now aside from all this stuff, what we have here in the designer tab is exactly what we need for the
‫game over text so we can duplicate this blueprint and change a few things.
‫I'm going to close out of it and here in the content browser I can right click on this WP Start Game
‫Widget Blueprint and duplicate.
‫Now we need to choose a new name for this widget.
‫I'm going to call this end game widget instead of start game widget.
‫So renaming this, we now have WPP End Game Widget.
‫Let's go ahead and double click this and we have the same text, get ready and it's called display text
‫and it's set to is variable.
‫Now let's go into the graph tab and we don't need any of this blueprint logic so we can highlight everything
‫and delete it.
‫In fact, we can delete the countdown variable.
‫You can always delete a variable by selecting it here and hitting the delete key.
‫So let's leave the display text.
‫We need that one and we can click compile.
‫And now we need to figure out how to set the text for this widget.
‫Now let's go to our game mode blueprint.
‫Here we have event game over.
‫This is where we can add the widget to the viewport.
‫So I'm going to highlight these nodes, the print string and the bool to text conversion node and delete
‫those and use a create widget node to add our new endgame widget to the viewport.
‫So I'm going to drag off type create widget and get that create widget node.
‫Now for the class, I'm going to select end game widget.
‫So we have WPP end game widget and the next thing to do is add it to the viewport.
‫So I'm going to click and drag off of the output execution pin and type add to viewport.
‫And now I can't forget that I need to take the return value from create widget and plug it into the
‫target for add to viewport.
‫So now as soon as our game over blueprint implementable event gets called, we will be adding this widget
‫to the viewport.
‫Now the last thing to do is to set its text based on whether or not we've won the game, which we know
‫because we have this boolean from our event game over.
‫So we need to think about what to do once we've won the game.
‫Now we know that we can use a set text node to set the text of a particular widget.
‫In our widget blueprint, we need to be able to access that text widget, which we called display text.
‫So what we can do is from our Create Widget blueprint, the return value, which returns a WPP end game
‫widget object reference can be used to access variables in that widget.
‫So let's click from the return value and drag off and type display text and we'll see that we can get
‫display text from there.
‫We can use a set text to Node.
‫So let's click the output from display text, drag off and release and type set text and we can see
‫that set text, parentheses, text is an option here.
‫Now just to test this out, just after we've added the end game widget to the viewport, we can hook
‫up the execution pin to a set text node where we can set the display text text value.
‫So for now, I'm just going to type game over and now with a compile, I'm going to play test this and
‫see if we can get that widget showing up on the screen.
‫So I'll go ahead and let these turrets kill me and now I see game over.
‫But for me that's not quite enough.
‫I'd like to see if I've won or lost the game.
‫Now there are various ways to do this, and you may even think that you have an idea in mind regarding
‫how to set this text value.
‫In fact, you might even wish to pause the video and see if you can implement this yourself.
‫So if you feel like the challenge, go ahead and pause the video now and see if you can figure this
‫out.
‫Okay.
‫So if you figure this out, congratulations.
‫You have implemented the game over widget.
‫Now I'm going to show you a special node that I'm going to use.
‫And you may not have seen this before, but this node is called a select node.
‫I'm going to right click and type select.
‫And if I select, select, I have this node that takes an index.
‫The index is a value which will determine what gets selected and returned as the return value.
‫And I can click the dropdown and select boolean and for the return value I can right click on it and
‫select change pin type.
‫And then I get this dropdown that says Wild Card and I can change this to a different type of output
‫value such as text.
‫So I'm going to select text and now I have this select node that has a true and a false input as well
‫as the index, which is a boolean.
‫And the true false and return values are text values.
‫They have the text data type.
‫Now the way the select node works is we have an index and we selected Boolean as the type for this input,
‫which means we can plug in a boolean value and the return value will be different depending on the value
‫of the index.
‫If the value of the boolean is true, then we will return a text value depending on the true input for
‫the select node.
‫And if it's false, we'll get the value assigned to the false input.
‫Now these are input pins for true and false, so we can plug in text values to them directly, or we
‫could hard code them in the text boxes.
‫For example, we can type in text you lost for false and you won for true.
‫And what we get returned from this select node depends on that input index.
‫If it's true, then the return value will be u one.
‫And if it's false, we will get you lost.
‫So if you haven't implemented the solution already, I'd like you to try using the select node to do
‫so.
‫So use a select node and set the false text to you.
‫Lost.
‫Set the true text to you one and hook up the player one boolean which we get from our game over event
‫resulting from our blueprint.
‫Implementable Event Game over.
‫Once you've done this use set text to set the widget text, pause the video and implement this now.
‫Okay.
‫So I have my select and I need to hook up the index which is a boolean and I'm going to use one game
‫from the event game over.
‫Now based on this input boolean, I'll get a different return value depending on whether the index is
‫true or false.
‫If it's true, I'd like to print you one with three exclamation points.
‫And if it's false, I'd like to print out you lost with a single exclamation point.
‫Now the return value.
‫I'm going to hook up to the set text node.
‫And now we should see you lost or you won, depending on whether we've lost or won the game.
‫So with a compile, I'm going to hit play and I'm first going to try to win the game.
‫So I'm going to try really hard not to lose.
‫There's the first second.
‫There we go.
‫And I see I won.
‫Now I can go ahead and try the lose condition, which should be pretty easy.
‫I just have to get shot twice.
‫There's one.
‫And there's two.
‫And you'll see that my tank disappears and I've lost the game.
‫Perfect.
‫So this takes care of the winning and losing conditions.
‫So in summary, we have displayed the game over status to the player and we're showing that in the form
‫of a text widget.
‫We now have a functional game, so this is a huge milestone.
‫The only thing left is the special effects.
‫We need some sound effects and we need some explosion effects and some weapon trails and things like
‫that.
‫So we're going to wrap up this game by adding those effects and polishing the overall game in the videos
‫to come.
‫So we're almost done with this section.
‫Great job and I'll see you in the next video.