extends Control var score = 0 var clickAdd = 1 var scorePerSec = 1 var scoreMultiplier = 1 var current_score: int = Global.globalDamage var target_score: int = 0 var animation_duration: float = 1 var elapsed_time: float = 0.0 var is_animating: bool = false # Called when the node enters the scene tree for the first time. func _ready(): $Timer.connect("timeout", _on_Timer_timeout) $Score.text = str(round(Global.globalDamage)) #Prints all input events, only for debugging #func _input(event): #print(event.as_text()) func _on_Timer_timeout(): #get the current score based on values before new calculation current_score = Global.globalDamage #update values on new calculation Global.globalDamage += Global.globalDamagePerSec * Global.globalDamageMultiplier update_score() pass # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): if Global.globalDamage <= 999: if is_animating: elapsed_time += delta var t = elapsed_time / animation_duration if t >= 1: t = 1 is_animating = false current_score = lerp(current_score, target_score, t) $Score.text = str(round(current_score)) else: $Score.text = str(format_number(Global.globalDamage)) #Puts commas in score, can't get it with animations yet #if Global.globalDamage > 999: #$Score.text = str(scoreFormat(current_score)) #else: #$Score.text = str(Global.globalDamage) #Changes the score number #print("Tween step: ", current_score) #update_score() $ClickAdd.text = str(Global.globalDamagePerClick) $PerSec.text = str(Global.globalDamagePerSec) $Multiplier.text = str(Global.globalDamageMultiplier) func update_score(): target_score = Global.globalDamage # Increment the target score (or set it based on your game logic) print("Update score called, target score: ", target_score) #Displays normal numbers until commas are needed #commented out for animation testing start_animation(current_score, target_score) func start_animation(from_score: int, to_score: int): print("Animating score from ", from_score, " to ", to_score) elapsed_time = 0.0 is_animating = true func format_number(n: int) -> String: if n >= 1_000_000_000_000: # ran for every number greater or equal to a trillion var i:float = snapped(float(n)/1_000_000_000_000, .01) return str(i).replace(",", ".") + "T" elif n >= 1_000_000_000: # ran for every number smaller than 1 trillion BUT # still greater or equal to 1 Billion var i:float = snapped(float(n)/1_000_000_000, .01) return str(i).replace(",", ".") + "B" elif n >= 1_000_000: # ran for every number smaller than 1 trillion BUT # still greater or equal to 1 million var i:float = snapped(float(n)/1_000_000, .01) return str(i).replace(",", ".") + "M" elif n >= 1_000: # ran for every number smaller than 1 million BUT # still greater or equal to 1 thousand var i:float = snapped(float(n)/1_000, .01) return str(i).replace(",", ".") + "k" else: # ran otherwise return str(n) #This checks any input that comes in func _input(event): #Function to record every left click as a "Click" to add to the score if event.is_action_pressed("left_mouse"): leftClick() #_on_button_pressed() #Formats the score string so commas are inserted func scoreFormat(score): # Convert value to string. var str_value: String = str(Global.globalDamage) # Loop backward starting at the last 3 digits, # add comma then, repeat every 3rd step. for i in range(str_value.length()-3, 0, -3): str_value = str_value.insert(i, ",") score = str_value return score func leftClick(): Global.globalDamage += Global.globalDamagePerClick * Global.globalDamageMultiplier update_score()