Easiest way to do toggling

Hi everyone,
I am learning some of that C++ for quite some time mainly with UE4. So yea...another one like me :D. I wanted to ask what is the easiest way to do toggling between multiple states. Let's say I want to by pressing E turn something on and it takes 5 seconds to be turned on. So if i press E again in five seconds I would pause the process and by pushing E again I would cancel it, then E again pause and so on and on. There is very handy blueprint in ue4 called multigate which is perfect for this, but I really want to do it in c++. I have an idea with a few variables but I feel like it is too complicated and so far I ve found much simpler solution on internet for everything I have done on my own. If you have any ideas I will be thankful. Thank you!

Hi,
So what program are you trying to make?
What do you want to / intend to do?
At first glance you could make an enum:

1
2
3
4
5
6
7
8
9
10
enum ObjectState { INACTIVE, ACTIVATED, PAUSED, STOPPED };
{
    // Inside function that handles 'E' button press
    switch(ObjectState)
    {
    case INACTIVE: ObjectState = ACTIVATED; break;
    case ACTIVATED: ObjectState = PAUSED; break;
    case PAUSED: ObjectState = STOPPED; break; // Once "Stopped" change to INACTIVE
    }
}


But without more information it would be hard to deduce the best method.
Topic archived. No new replies allowed.