Finite State Machines
Hello! For our first tutorial of the advanced series, we will be going over a concept called finite state machines. It sounds complicated, but don't worry, it's less complicated than you think! A finite state machine in games can be simply described as a table of behaviors that can happen according to certain parameters. In AI, this is used extensively. An example can be shown here:
This very simple example will produce an AI which will hunt for and attack the player, but only when they are nearby. RPG Maker can replicate something like this, but on a less granular level. Here it will be applied as a schedule for a NPC, at certain times of day, they will do certain things.
For this tutorial, we are going to be using the same project as the previous tutorials with some additions.
The start file can be found here: Project Start Download
Once you have that downloaded, go ahead and open it up in the editor and explore around. You'll notice some stuff has been added, namely this clock:

And this new apartment map:

These things will give us what we need to create our finite state machine.
First off, we need to create time segments for the game to utilize. There is no right answer for how to do this, but we're gonna go ahead and divide the day up into 4 pieces.
1. Morning
2. Day
3. Evening
4. Night
This will give us distinct time periods, several in which we can make the NPC not want to be disturbed and react appropriately to such an imposition! Now, let's put that clock from before to use. The clock will act as our "advance time" button for the purposes of this tutorial, but in a full game, you'll wanna make things more discreet than that.
Let's go ahead and create a new event on the lower half of the clock. The easiest way to make this work in my experience is to use a variable to represent the time of day, with 0 being morning, 1 being day, 2 being evening, and 3 being night.
Here is the code for our clock event:


This will now allow us to adjust the time of day forward one step by interacting with the clock in the hall. Now onto the interesting bit, creating our NPC!

Here's what I ended up with, yours doesn't need to look the same! I'm going to save these settings into our Faces folder that we made in the last tutorial series as Nadine.jsom. At this point, let's go ahead and export our walk character, then choose the no clothing option, import the clothed walk sprite that we exported first and then export it again so that we have a character image with a clothed and a nude Nadine on it, like so:

Let's go ahead and get some expressions for Nadine now, clothed and unclothed:

Now that that's done, we can close out of all the character creator windows. So now we just have to figure out what we want Nadine to be doing. Here's the schedule I came up with:
So let's go ahead and start with morning Nadine. Create a new event to the left of the bathtub in Nadine's apartment and call it Nadine - Morning. Set the image to the unclothed walk character for Nadine facing right. Set the Variable condition to the Time of Day variable we made earlier is greater than or equal to 0. Next, create a second page and leave it blank, except for the Variable condition being set to Time of Day is greater than or equal to 1.

The result of this is an event that only shows up when the time of day is 0, our morning time, which is exactly what we want. Next, let's copy this event and place the copy in the leftmost chair in the kitchen.

Now, let's edit that new event so that Nadine is clothed, and the Variable condition on both pages is appropriate to this event appearing in the evening. We can also change the name to Nadine - Evening.

One last time, let's copy the bathroom Nadine event and paste it onto the bottom tile of the bed in her room. Adjust all the settings as necessary and select the walk character corresponding with Nadine facing down.

At this point, let's go ahead and test this. Play through the gameplay we established previously in the tutorial series up to the point where you can leave your apartment and make a save, so that you don't have to play it again (unless you want to).
It looks like everything works, we've got Nadine moving around her apartment at different times of day and we have all that we need in place for her to react to the player's presence in her home at those different times!
This is a very small scale representation of what can be done with this system, and it can be easily scaled up to a full game if you like. Your challenge now is to write the code for what Nadine does to the player when interrupted. The final version of this project will contain my interpretation, but I'd like to see what you guys come up with! If you find yourself needing help or ideas, feel free to take a look at the code we already wrote for ADA.
Happy eventing!
This post was made possible by all of my generous (and attractive) patrons!
Godspeak
2018-03-03 05:33:16 +0000 UTCBabyluka
2018-03-03 03:36:50 +0000 UTC