Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Panel
- ##TO DO
- ##Create a script that can correctly convert the countdown timer from seconds
- ##into minutes, seconds, and miliseconds.
- ##There doesn't appear to be a property for the timer class for this in the
- ##Documentation so we will need to do this ourselves.
- ##Once we have the time remaining converted properly we can then get to work
- ##Displaying it on the UI.
- #using an export varible to set Timer.wait_time so I don't need to go between
- #tabs so much.
- static var timerWaitTime : int = 120
- #storing timer as a var incase we need get and set functions later down the line
- @onready var countdownTimer := $countdownTimer
- #first approach we're going to do will involve storing minutes, seconds and
- #milliseconds as seperate varibles which we will then set as label text.
- var timerMinutes : int
- var timerSeconds : int
- var timerMilliseconds : int
- func _ready():
- countdownTimer.wait_time = timerWaitTime
- countdownTimer.start()
- func _process(delta):
- #take wait_time property and truncate the time so we are only left with whole seconds.
- #We can deal with the fractions of a seconds later.
- timerSeconds = int(countdownTimer.time_left)
- #print("Seconds remaining: ", timerSeconds)
- timerMinutes = timerSeconds / 60
- #print(timerMinutes)
- #Subtract the remaining minutes so we're only left with the seconds
- for minutes in timerMinutes:
- timerSeconds -= 60
- var timerOutput : String
- #cant think of a way to run this through a switch case in a way that isnt
- #stupid so I'm using if else
- if timerSeconds <= 9:
- %TimerLabel.text = str(timerMinutes, " : 0", timerSeconds)
- else:
- %TimerLabel.text = str(timerMinutes, " : ", timerSeconds)
Advertisement
Add Comment
Please, Sign In to add comment