extends CharacterBody2D
@onready var time_display: Label = $"time-display"
@onready var throttle_display: Label = $"throttle-display"
@onready var stopwatch: Timer = $stopwatch
var throttle = 0
var time=0
@onready var started=false
func _process(delta: float) -> void:
#throttle-handlers
if Input.is_action_pressed("throttle_up"):
throttle +=10
started=true
elif Input.is_action_pressed("throttle_down"):
throttle-=10
if(throttle < 0):
throttle=0
if(throttle > 500):
throttle=500
throttle_display.text="Speed: "+str(throttle)
time_display.text="Time: "+str(time)
if Input.is_action_just_pressed("throttle_up") and (started==false):
stopwatch.start()
started=true
func _physics_process(delta: float) -> void:
#speed-handler
velocity.y=throttle
move_and_slide()
func _on_time_timeout() -> void:
time+=.5
stopwatch.start()
This was the problem:
The timer started wasn't working, I realize I didn't specify that in the first post. The reason is because the 'if button pressed and variable at this' was below other if queries, but when I tried to change it to an elif I got the error 'expected statement but got 'elif' instead'. I don't know why, but moving it to the top of the code didn't mess anything up, and seemed to fix the problem.
Let me know if you have any other suggestions.