help me with my code

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

I have a script which should check when a button is pressed and add the new ship . The code runs till it reaches the 2nd if statement (shipT3) the if statement runs as if I place a print statement it runs but the shipT3 isn’t added
here is my code:

var new_spaceship
var spaceship_tier = 1 # the current tier of the spaceship
var cooldown = 0
var allow_proceed = false 
var remove_spaceship = false
var stop_minusing_coins = false
var cooldown1 = 0
var cooldown2 = 0
var cooledown_bool = false
var kill_if = false
func _on_upgrade_button_pressed():
	if varia.spaceship2:
		if spaceship_tier <= 1 and varia.new_ship != true and varia.coins >= 20:
			var spaceship_scene = load("res://scenes/player_rocketT" + str(spaceship_tier + 1) + ".tscn")
			var current_spaceship = get_node_or_null("main/rocket_player")
			new_spaceship = spaceship_scene.instantiate()
			varia.remove_spaceship = true # global variables removes old ship and start  the cooldown1 timer
			add_child(new_spaceship)
			new_spaceship.position = varia.position # gets the position of the spaceshipT1 and sets it to a vector global variable
			varia.new_ship = true # so the first if statement runs once (global variable)
			varia.coins -= 20 # removes the coins from the global coin counter
		if varia.new_ship and varia.coins >= 40 and varia.remove_spaceship == true and remove_spaceship != true and varia.remove_spaceship2 != true and cooldown1 >= 10:
			var spaceship_scene = load("res://scenes/player_rocketT" + str(spaceship_tier + 1) + ".tscn")
			var current_spaceship = get_node_or_null("main/rocket_player")
			new_spaceship = spaceship_scene.instantiate()
			varia.remove_spaceship2 = true # removes the spaceship tier 2 (global variable)
			add_child(new_spaceship)
			new_spaceship.position = varia.position # sets its position to the position of the spaceship T1 before it was removed
			allow_proceed = true
			remove_spaceship = true
			if stop_minusing_coins == false: # so only 40 coins is detuctted from the coin count
				varia.coins -= 40
			stop_minusing_coins = true  # so the if staement runs once
			spaceship_tier += 1
	
		if varia.new_ship and cooldown >= 10 and varia.coins >= 120 and varia.remove_spaceship2 != false and allow_proceed and kill_if != true:
			var spaceship_scene = load("res://scenes/player_rocketT" + str(spaceship_tier + 1) + ".tscn")
			var current_spaceship = get_node_or_null("main/rocket_player")
			new_spaceship = spaceship_scene.instantiate()
			varia.remove_spaceship3 = true # remove spaceship tier 3 (global variable)
			add_child(new_spaceship)
			new_spaceship.position = varia.position # sets position to the global Vector
			spaceship_tier += 1
			kill_if = true # so this if statement runs once
			varia.coins -= 120
			cooledown_bool = true # so there is a cooldown before you can upgrade the shi[
			
		if varia.new_ship and cooldown2 >= 10 and varia.coins >= 240 and varia.remove_spaceship3 != false:
			var spaceship_scene = load("res://scenes/player_rocketT" + str(spaceship_tier + 1) + ".tscn")
			var current_spaceship = get_node_or_null("main/rocket_player")
			new_spaceship = spaceship_scene.instantiate()
			varia.remove_spaceship4 = true # removes the spaceship T4
			cooledown_bool = true
			add_child(new_spaceship)
			new_spaceship.position = varia.position # sets it position
			varia.coins -= 240

func _process(delta):
	if new_spaceship != null: # so the code won't crash
		new_spaceship.position.y = 650# as a failsafe sets te position to the regular play position
	if allow_proceed: # this is the cooldown that runs 
		cooldown += 0.1
	if varia.remove_spaceship == true: # this is the other cooldown 
		cooldown1 += 0.1
	if cooledown_bool: # this is the other cooldown
		cooldown2 += 0.1

	
func _on_texture_button_pressed():
	_on_upgrade_button_pressed()

all and any help is appreciated
if you need the code of the spaceshipT3 or anyother please tell me
thanks any and all help is apreciated

Edited to fix code formatting…

jgodfrey | 2023-04-07 21:25