About 'Manage Next States'!

In this video (objectives)…

  1. Create a small game loop by having each state lead to another state.
  2. Create a method to respond to player's key input.
  3. Update the game's state based upon the next state array options.

After watching (learning outcomes)…

Complete our small adventure game engine using player input and state flow.

(Unique Video Reference: 10_TX_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Oh my gosh! Unity makes organizing and sorting huge amounts of data so easy! I’m so happy I’m almost crying! Why didn’t I try this years ago?!

Thank you for offering these courses. I never would have seen the beauty of this kit otherwise!

1 Like

I think there is something worth pointing out here. I think the last else if with the “Alpha3” KeyCode is unnecessary. There are always only two next rooms when there are three rooms in total for this part of the course. So the third one may be confusing for some people.

So, I got a little ambitious with my text adventure, but a lot of this is replicating states to account for variables. I’m trying to figure out how to turn some of these states into boolean triggers that I can then hang different states on, instead of building a whole new world for each possible combination of triggers. So, in the yellow, there are 3 possible things the player can do to change something in the world, if I could simply change the state of, for instance, vaseShattered = True, then I don’t have to rebuild the entire world for the player to navigate in which the vase is shattered, and instead, I’d only have to change the state of Vase0 to DeadVase. If I could do that, I could quadruple the size of this and make the game that I really want to make. I’m not even sure if that’s possible, but I thought I’d ask. I would really appreciate any advice, thanks!

3 Likes

Just finished this part and for me the easiest way to update the text on a key press (which will allow quite a few options) is to do the following

private void ManageState()
{
    var nextStates = state.GetNextState();

    int NumericValue = -1;
    int.TryParse(Input.inputString, out NumericValue);
    if (NumericValue >= 1 && NumericValue < nextStates.Length + 1)
    {
        state = nextStates[NumericValue - 1];
        UpdateText();
    }
}

This will allow you to type any number from 1 to the number of states you have, the tryparse will make sure you have typed a valid number. The UpdateText() method is simply

private void UpdateText()
{
     storyTextComponent.text = state.GetStateStory();
}

I would also say that calling the ManageState() method every frame would be a bit of an overhead so I also decided to change the Update method to the following.

void Update()
{
    if (!string.IsNullOrEmpty(Input.inputString))
    {
        ManageState();
    }
}

This will only call the ManageState method if a key is pressed.

Onwards to the next part :slight_smile:

This might not be helpful exactly, but duuude! Nice!

Aaand Here’s my flow chart! That was fun!

2 Likes

This is awesome, can I play it?

Hey, thanks for the replies! It’s not even close to being finished, but I will absolutely share it when i’m done!

1 Like

3 posts were split to a new topic: Problem creating method

Privacy & Terms