- Edited
I am working on a project for my computer science class in high school, I have two timers set up, and one is supposed to start after the other and they go back and forth for as long as the game is running and the node containing their code is active.
Here is my code:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
#Timer1 start
if moveActive == true && moveTimer >= 0:
moveTimer -= delta
print("moveTimer")
#timer start
if moveTimer <= 0:
stopTimer = maxStopTimer
stopActive = true
moveActive = false
while stopActive == true && stopTimer >= 0:
stopTimer -= 1;
print(stopTimer)
#hen one is true do it, then turn it off hen you have it reach 0
if stopTimer <= 0:
stopActive = false
moveTimer = maxMoveTimer
moveActive = true
velocity.x += moveSpeed
The first timer is using an if statement, but in order to work, the second timer needed to be a while loop, and everything works, but the while loop goes to fast for normal numbers to be used as an effective timer, and when you raise the number to one that works, it goes so fast that the game stutters and lags.
It's a little weird but the system I have checks most of the boxes for the project I just need the second timer to work.