No Errors but code not working, Unable to progress with my adventure

I’m coding my text adventure and can’t seem to see where I’ve gone,
it works up until leaving the room. then my actions don’t work

code here

This is my code, can anyone see where I’ve gone wrong?

Steps to reach issue:-

Press X
Press T
Press C
Press O

Now you should be at page that says "Amber light engulfs you"
Z doesn’t take you to the next path

Can’t really see anything wrong with it right now, I’m on my phone right now so it’s a bit hard to see but will have a look when I get home. :slight_smile:

After which state does it stop working?

Thank you for replying!

It stops working after -

void corridor_0()

Much appreciated!

you have to add the corridor_1 state to the update:

void Update () {
        print (myState);
        if (myState == States.cell) {cell();}
        else if (myState == States.table_0) {table_0();}
        else if (myState == States.table_1) {table_1();}
        else if (myState == States.lock_0) {lock_0();}
        else if (myState == States.lock_1) {lock_1();}
        else if (myState == States.corpse) {corpse();}
        else if (myState == States.cell_key) {cell_key();}
        else if (myState == States.corridor_0) {corridor_0();}
        // SHOULD ADD HERE THE else if (myState == States.corridor_1) {corridor_1();}

Thank you for your response, I’ve just tried but no success

Try using Input.GetKeyDown(KeyCode.Z) instead of Input.GetKey(KeyCode.Z)

1 Like

are you sure? this code below should fix it :frowning:

void Update ()
{
        print (myState);
        if (myState == States.cell) {cell();}
        else if (myState == States.table_0) {table_0();}
        else if (myState == States.table_1) {table_1();}
        else if (myState == States.lock_0) {lock_0();}
        else if (myState == States.lock_1) {lock_1();}
        else if (myState == States.corpse) {corpse();}
        else if (myState == States.cell_key) {cell_key();}
        else if (myState == States.corridor_0) {corridor_0();}
        else if (myState == States.corridor_1) {corridor_1();}
}
1 Like

I concur with @Joao_Dalvi, you need the logic to handle this state in the Update() method.

…and I concur with @Rivaldragon too, your button press wont be being recognised… two issues - well spotted guys :slight_smile:

Updated my code with your suggestions, and it still won’t progress further than "Amber Light engulfs you,

Updated link

I really hope we can spot the issue!

Can you check the link? I’m not being able to access it

That should work now :slight_smile:

it is missing an opening parenthesis here:

 void corridor_0() {
        text.text = "You're in the corridor!\n" +
            "Amber light engulfs you.\n\n" +
            "Press Z to continue";
        if **>> <<**Input.GetKeyDown(KeyCode.Z)) {myState = States.corridor_1;}

Oh my, it’s still not working. I’m not sure how I’ve messed this up so much.

Hey, no problem :slight_smile: this happens all the time to most of us :joy:

So, the compiler is returning any kind of error? Or it just don’t change the state after corridor_0?

If it is returning an error, would you mind pasting it?
Otherwise, we can debug and look for it adding a print to the if statement under corridor_0 like this:

Wow this community is so nice!

@Joao_Dalvi It’s not returning an error, it’s just not proceeding passed the corridor_0 statement!

Pasted that line of code, still doesn’t run =[

1 Like

The line inside the print appears in the console when you press Z while under the corridor_0 state?

Doesn’t seem too

well, if nothing is appearing within the console when you press Z and if the text under corridor_0 is appearing, seems that the error is within the if itself:

would you mind trying different keycodes and see if it run? something like:

If this don’t work, try taking out the if statement and just put straight and see how it behaves:

let’s try to find where is the problem

Ok, so I’ve done this, and the issue remains the same!
The console is showing corridor_1 playing in game, climbing to over 80000 in console

Privacy & Terms