The Next Screen Text Won't Show Up!

Hey everbody!

TextController.cs

public Text myText;

private enum States {intro, cell, sheets_0, sheets_1, lock_0, lock_1, mirror, cell_mirror,
                    corridor_0, corridor_1, corridor_2, corridor_3, stairs_0, stairs_1,
                    stairs_2, closet_door, in_closet, floor, courtyard}
private States myStates;

// Use this for initialization
void Start () {
    myStates = States.intro;
}

// Update is called once per frame
void Update () {
    print (myStates);

    if      (myStates == States.intro)          {intro();}
    else if (myStates == States.cell)           {cell();}
}

// Introduction
void intro () {
    myText.text =   "Welcome to Prison, a text adventure game\n\n" +
                    "Press (Space) key to start.";

    if      (Input.GetKeyDown(KeyCode.Space))   {print("Space key pressed!"); cell();}
}

// Cell
void cell () {
    myText.text =   "You are in a prison cell, and you want to escape. " +
                    "There are some dirty sheets on the bed, a mirror on the wall, " +
                    "and the door is locked from the outside.\n\n" +
                    "Press (S) to view Sheets, Press (M) to view Mirror, Press (L) to view Lock.";

    if      (Input.GetKeyDown(KeyCode.S))       {print("S key pressed!"); sheets_0();}
    else if (Input.GetKeyDown(KeyCode.M))       {print("M key pressed!"); mirror();}
    else if (Input.GetKeyDown(KeyCode.L))       {print("L key pressed!"); lock_0();}
}

The problem is that I start the game, the first screen show up the text but when I press a button to continue to the next step, the next step’s screen show up for almost a second then the screen returns to the original one when the game started.

I managed to do all the work successfully on my own, and when I press B in MonoDevelop it states that the Build Succeed. Personally I think that there is something wrong with the Update section, but can’t figure it out.

Can someone help me with this?

Thanks in advance!

1 Like

To me it seems the myStates is never updated.

This is my (working version) not translated to English, but you’ll get what I mean

if (Input.GetKeyDown(KeyCode.T)) {mijnstaat = States.P0_table; }

Looking at your intro state it looks like you are going to Cell() but your update has no idea that

(myStates == States.cell)

Just my initial reaction, hope it helps you

1 Like

Just to be aware, you can copy/paste your code directly into the forum, this can make it that little more straight forward for people offering to help. :slight_smile:


See also;

I get what you are trying to say, but what I did on top of what the instructor did was adding Intro. Without Intro it did the same thing just can’t get to the next screen.

Should I put the code here, even if it’s too long? Because I don’t know specifically where the problem is!

Yes, that’s fine. Please make sure you read the info I gave you the link for with regards to formatting, it’s really easy to apply and it will put your lengthy code in a scrollable area, so you don’t have to worry about the length of a post.

If you want to add multiple scripts, then just close the code block with the formatting characters (```) and start a new one, for example;

AnExample.cs

// imagine this was a really long code block

AnotherExample.cs

// image this is another code block

You can see above I have added the script names, just in text but to separate the scripts also, just for readability.

Hope this is of use :slight_smile:

Your current problem:
myStates is not changed
The Update() sees that myState == States.intro so will take you to intro() again

Please read my previous post carefully:

  • Your myStates is never changed:
  • On the press of a key. YOU SHOULD UPDATE myStates.
  • the Update() method, will then take you to the next method like cell().

Perhaps try watching Lecture 32 again.

And maybe use CAPS for the first letter in your Methods() but i’m not sure to what extend that is part of the problem.

Also, if you post until the void cell() method that should provide plenty of information.

Thank you so much, now I read carefully what you said in the previous post and it’s working just fine.
It seems that I didn’t understand the work of operations in the first place, that’s why I forgot what to use in this context.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms