Why isn't this working?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Darkerzap

So I finally figure this out but I have a problem. This code here
if Global.Notation[0].length() > Global.MAX_DIGITS:
$Label.text = “Wasted Time: %se%s” % [String(Global.WTTN), String(Global.WastedTimeTotal).length() - 1]
$Label.text = "Wasted Time: " + str(Global.WastedTimeTotal)

Sits under _process which I though updates constantly but this code that is suppose to change WastedTimeTotal (My currency) into Scientific Notation once it hits 11 digits long
only works if I change the currency in the script to the 11 digit mark.
So if my WastedTimeTotal = 10000000000 then it will show 1e10 on load
but if I have WastedTimeTotal = 9999999999 and use a button to add one to push it to 11 digits long it doesn’t change to 1e10. Just in case it’s needed here is my full code.

This is my main code

extends Node2D

func t(time):
return get_tree().create_timer(time)

func _ready():
#Sets the Superhero Progress bar when swapping back to Game Screen

func _process(_delta):
#Checks if Time Wasted Total is greater than the maximum digit limit if so reduced to scientific notation
if Global.Notation[0].length() > Global.MAX_DIGITS:
$Label.text = “Wasted Time: %se%s” % [String(Global.WTTN), String(Global.WastedTimeTotal).length() - 1]
$Label.text = "Wasted Time: " + str(Global.WastedTimeTotal)
#Allows the Superhero Progress to increase
Global.SuperheroTotalProgress = $Superhero/SupheroProgress.get_value()
#Resets Superhero Progress to 0 when bar is full and disables the
#Superhero Button until process is done
if $Superhero/SupheroProgress.get_max() == Global.SuperheroTotalProgress:
$Superhero/SupheroButton.disabled = true
yield(get_tree().create_timer(.05), “timeout”)
$Superhero/SupheroButton.disabled = false

func Suphero_Button_Pressed():
#This adds Wasted Time for each click of the Suphero Button
Global.WastedTimeTotal = Global.WastedTimeTotal + Global.WT_Per_Superhero_Click
#Sets the value of the Superhero Progress bar to + “1” for each click

#Switches to Upgrades Screen
func _on_Upgrades_pressed():
Global.goto_scene(“res://Game Screen/Upgrades.tscn”)

#Switches to Upgrade Screen
func _on_Microtransactions_pressed():
Global.goto_scene(“res://Game Screen/Microtransaction.tscn”)

My Global Code
extends Node2D
#Total amount of Wasted Time (Main Currency)
var WastedTimeTotal:float = 10
#Amount of Wasted Time from clicking the Superhero Button
var WT_Per_Superhero_Click:float = 1000000000
#Turns the total amount of Wasted Time into a string
var WTT = str(WastedTimeTotal)
#Uses the string above to pull the first number from the float
var WTTN = float(WTT[0])
#Stops player from desyncing Supherohero Button and Progress
var timer
#How much the Superhero progress bar is at out of max
var SuperheroTotalProgress:float = 0
#How much the Superhero Button Increases per click
var SuperheroIncrease:float = 1
#Used to turn Wasted Time into a String then used to count all places after the first number for Scientific Notation
var Notation = String(WastedTimeTotal).split(“.”, false, 1)
#How many total numbers are allowed before being turned into notation
const MAX_DIGITS: int = 2
#Don’t know really copied this guessing it’s for scene change
var current_scene = null

func _ready():
#Both lines are for scene change
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() - 1)

func goto_scene(path):
# This function will usually be called from a signal callback,
# or some other function in the current scene.
# Deleting the current scene at this point is
# a bad idea, because it may still be executing code.
# This will result in a crash or unexpected behavior.

# The solution is to defer the load to a later time, when
# we can be sure that no code from the current scene is running:
#Scene change again
call_deferred("_deferred_goto_scene", path)

func _deferred_goto_scene(path):
# It is now safe to remove the current scene

# Load the new scene.
var s = ResourceLoader.load(path)

# Instance the new scene.
current_scene = s.instance()

# Add it to the active scene, as child of root.

# Optionally, to make it compatible with the SceneTree.change_scene() API.

PS: In the future, please use more a descriptive title for your questions instead of “Why isn’t this working?”.

Calinou | 2020-12-17 00:55