I notice people tend to miss this. Code is an In ORder of operation. You must have a data of logic flow. You example actually is very clear on the error made.
if(state = 1) then state = 2
if(state = 2) then state = 1
the Keyboard on pressed state will be TRUE for the entire tick and not just one event. So we can technically just view the two lines of code as always true.
So let's re-examine those lines
Layout start: state = 1;
if(state = 1) then state = 2 // now the state is 2
if(state = 2) then state = 1 // since the state was set to 2 in the last line. The condition is now true. Now state =1 is being set.
so in the same tick of Pressed you evaulate both condition as true.
Instead what you want is
Event: If P is Pressed
Sub Event: if state == 1 then state = 2
sub Event: if state == 2 then state =1
actually you can skip the if state==2 as the ELSE condition covers that.
Also when you need to pause make sure to set yout timescale to 0 :)