Kyle Pollard
Kyle Pollard

Reputation: 2323

How do I manually restart a one shot Timer?

I've added a one shot Timer and hooked up a function to listen for the timeout() signal. After some action occurs in my game, I want to restart the timer at its original Wait Time value.

I've tried resetting the timer to the Wait Time I set in the inspector like this:

$Timer.time_left = $Timer.wait_time

This results in an error:

Invalid set index 'time_left' (on base: 'Timer') with value of type 'float'.

How do I set the time back to its original Wait Time value in the inspector?

Upvotes: 2

Views: 5106

Answers (1)

Kyle Pollard
Kyle Pollard

Reputation: 2323

Looking at the documentation for Timer, it says that you can't set the time_left property and should instead use start:

Note: You cannot set this value. To change the timer's remaining time, use start.

Calling start without any parameters restarts the timer to its original Wait Time value:

$Timer.start()

The start method also takes in an optional time_sec parameter that could instead restart the timer to a new wait time:

$Timer.start(0.5)

Upvotes: 2

Related Questions