I've been trying to make my code work for some time, but I can't seem to find a way to make it work, specifically, I can't find a way to make an object wait in an if statement or find a viable alternative to one. Essentially, I've been trying to make a game object move to the right for 2 seconds, and then go back to it's original coordinates once that movement is finished. I'm pretty new to GML, but I figured something such as x += 2 was what i was searching for in terms of moving the object to the right. However, I can't find a way to make said object execute x +=2 only once once pressing the control button (because it keeps sliding to the right as long as I press it, it doesn't just make a swift movement to the right), then wait in place for 2 seconds. I've tried making if statements as intricate as I could make them, but to no avail. If anyone has any idea, i'm excitedly open to it. Have a good day.
You are probably looking for a timer, to let the object wait before an action. In that case, this question may help: Delay time in GMS2
I would not recommend your current approach (using a while
loop to wait until the timer is finished), as that will put all the code and actions in the object event on hold until that while function is done.
You should also look up the difference between a button 'press', and a button 'pressed'.