Creating Function! Not working Properly

PaulS:
It works when the code is in loop() because the changes to state affect the global variable named state, not the function argument named state. I told you that changes made in the function are lost, but you seem to have ignored that.

Google pass-by-reference and pass-by-value to understand passing data to functions.

Sorry if it seems that i ignored you but i didn't, i tried making the variables global and that still didn't work, I'm trying me best to understand i've been programming a few days actually but anyway thanks for the info. I will look into it