[SOUND] In this video, we're gonna get some context for what states are and
state machines are, and write ourselves a little bit of our first
state of our story and our first decisions for the player.
So let's jump in and have a look at states and state machines.
In order for us to create an interesting text adventure game,
we're gonna need a lot of text and a lot of adventure, to state the obvious.
To do that, we are going to need to organize our bits of information,
our pieces of the story to give to the player.
We're gonna need a good way to organize our states.
But what do I mean by states and what do I mean by state machines?
Well, a state is an action or a process or
a behavior, the thing that we are doing usually.
A state machine assumes only 1 state at a time.
I'll show you a state machine in a moment.
And conditions, in other words,
requirements, transition from one state to the next.
So that's state, and state machines, what do we mean?
You'll see the start symbol here, we'll lead into our first state, so
this is state A we'll call it.
And from state A we have a decision.
This diamond is a symbol in state machines used to symbolize a decision point.
From the decision, we might say, Yes, from our decision and
that leads us to State B which is a different state to State A, State B, or
might say No, that leads to State C.
Let's make that real with some examples here.
So from our Start, we might with a Room with 2 exits,that might be our state.
And we would have in our game some text, some flavor to that.
It could be you stroll into a room, there is a smell of burned toast in the air.
Does that mean there's something wrong with your brain or
does that mean that someone is cooking toast?
Whatever it might be, I just made that up on the spot,
that's why it wasn't so clever.
But, [LAUGH] so our first state is, you're in a room there are 2 exits.
So the player has a choice, choice is very, very important in games,
we have a choice.
Which way do you go?
That's what we present to the player.
To the Blue Door represents the Real world.
And then we would go into the next state, and in that next state we would say,
you've entered a world that looks very real and tangible and photo-realistic.
If you were to choose the Red Door for example, might be like go to fantasy land.
You walk through the door and
you are encountered with a whole bunch of people who address brightly and
dancing around and having a wonderful time, whatever our story might be.
So, this is our state machine, and this suggest 3 states and 1 decision point.
In our game it's gonna be much, much bigger, you go through a door,
you go in another room, maybe have some conflict, do you go left, do you go right?
Do you do this, do you shoot the person, do you run,
do you climb up the ladder, all these different states,
all these different conditions, all these different transitions.
So we may have hundreds of states,
each state may have many lines of story within it.
So, it might have a lot more text,
a lot more of that flavor that I am talking about, in out text adventure.
Descriptive elements to it and
we need a way to manage all this data as I was saying before.
So, this is our problem, almost specifically our requirements and
we need to come out with a solution.
If we are doing this all within a single text file that's managing all this states,
we would have all of these states.
And then for each of these states, we would have the text that's required.
We need to some concatenation here, which is where cuz we can't fit
outline all the way across here but we're not about to read it.
After all so we have to break it up and then we need to, for
each of these states we need to say what the key input is every single time.
So there's sort of repeated code, there is a lot of typing in text into that text
file and there is a lot of if something goes wrong somewhere in here,
then it could break the flow.
And there is also a difficulty in keeping track of okay,
this state down here lock_0 from there I want to go up to stairs_2.
But also I want to transition into corridor_0.
So, this is a valid way for us to organize our story and our state, but it's a little
bit difficult and a little bit clunky to use and it doesn't scale very well.
So our approach will be to use scriptable objects, and
that's what we'll talk about in the very next lecture.
This lecture, I just wanted to give you the context of our state machine and
to give you a quick challenge, which was to come up with your starting state.
So what is the first thing that your player is confront with?
What's the first piece of text in your game
that you're going to give to the player?
Now later on, we're gonna talk a little bit more about game design and game float
to manage your state machine and how you can create that in a nice tool.
I'll give you my input on a good tool to use to create that but
for now we're saying something pretty quick.
We're saying what's the first state to get the ball rolling, so we've got something
to enter in the next video when we're talking out that first state.
So, come up with 2 or 3 sentences that will start your game.
For example, you walk into a room, you smell, what did I say before?
You smell burnt toast, it could be that,
it could be even cleverer than that, perhaps.
And what are the 2 choices your player can make?
So this is important at the start,
let's think about what choices are you going to give your player?.
What format should you write this up in?
And let me give you a quick little idea, here.
If you are into Visual Studio and right up to the top New
> File, you can choose a Text File.
So, double click on Text File, and here we get a blank text file.
It's not gonna have any of the autocomplete and
any of the errors that we would have if we were in a C Sharp's file or a .CS file.
We can just type in here, so type in the first couple of
sentences and then here are the 2 choices.
So go ahead and create your first couple of sentences for your story and
first 2 choices.
When you've done that I'll see you back in here in a moment and
I'll give you a quick taste of what I've come up with just very quickly.
Welcome back, this is what I've written, little bit of dialogue at the top here.
You can read that if you want, but I'd like you to do something that is your
story, and not just follow what I've done with mine.
I've said there's a whole bunch of stuff going on, I could try doing A or B.
What should I do, take them head on or to sneak my way to the emergency exit.
So, this is going to give us some text, little bit of real context when we're
creating our states in the upcoming videos and starting up.
Now, if you wanna save this, you should probably say you lose it Files > Save As.
I'm gonna save mine right in my Unity project just so it in there,
this is not typically behavior, normally we don't use text files to keep notes and
save them within Unity.
But I wanted to make sure that no matter what platform you're operating on or
operating system you have, or what you've installed on your computer,
that you absolutely would be able to follow along with this lecture.
And you weren't racing off trying to find a text file editor or some other thing and
figuring out what to do.
So I'm gonna save mine just in the assets folder here and
call it First state of my game.
And then save that, and interestingly, if we jump back over into Unity,
you will see, we have this text file, which is the first state of our game.
Which is pretty handy to have, it's right in the middle of our Unity file,
keeping it nice and organized to remind me where it is.
We're not gonna do that long term, this is just to keep some notes,
this is not something we would use in our game.
Okay, great work in this lecture, I'll see you in the very next video.
We're gonna be talking about scriptable objects.
See you soon.