[solved] how to keep count of each time I look at door

I am building the engine for the Text101 game we are making, I am going with my own story line but I want to keep track of each time a player enters certain states (E.G each time the player looks at the door I want the door counter to go up by 1)

you can find my code so far here

I already have int door declared before void start. inside of void start I have door = 0 and each time I look at the door I want that number to go up by one

what I have tried

door = door + 1
door++
door += 1
door =+1

all these options make the door number continuously go up by one every screen refresh however I want it to only go up by one.
one option (door =+1) will make it only go up to the number 1 and stop but then when I exit and renter the door state it is still only at 1 and not at 2

my question is how can I make my door counter go up by 1 each time I look at the door then how can I keep track of that number

just some added info the door counter is not going to be viewed by the player.

any help is appreciated thank you all!

The issue you are experiencing is because within the Update() method you check for the state and then fire the corresponding method, but many times.

You are incrementing the counter with one of those methods, thus that happens many times also.

You could;

  • use a class level variable as a flag to indicate whether or not you had incremented the counter, wrapping it up in an if statement in the appropriate method

  • change the game structure so that it doesnt make repeat calls to the methods which display the story, but you would still need to keep checking for the correct key presses for the user options

or;

  • put you counter which increments into the if statement which sets the state of looking at the door, e.g. set it upon the keypress before you arrive at the door.

thank you so much!

1 Like

You are welcome Micah :slight_smile: