Texture Button is pressed but scene doesn't change

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BainBan
the sounds plays but the scene doesn't change, I don't know what to do. I'm a beginner Basically it is a plane shop in my game, but the scene doesn't change. Appreciate any help!

This is my code:
`

extends Control
onready var default_plane_button = $DefaultPlaneButton
onready var plane_1_button = $BuyPlane1
onready var plane_2_button = $BuyPlane2
onready var plane_3_button = $BuyPlane3
onready var plane_4_button = $BuyPlane4

func _on_BuyPlane1_button_up():
var read_dictionary = str2var(change_file().get_as_text())
var new_dictionary = read_dictionary
if new_dictionary[“plane_1_bought”] == true:
new_dictionary[“plane_equipped”] = 1
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_1_button.text = “Equipped”
elif new_dictionary[“coins”] >= 1000:
global.button_click_sound.play()
new_dictionary[“coins”] -= 1000
print(new_dictionary)
new_dictionary[“plane_1_bought”] = true
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_1_button.text = “Equip”
else:
print(“insufficient coins”)
global.no_click_sound.play()

func _on_BuyPlane2_button_up():
var read_dictionary = str2var(change_file().get_as_text())
var new_dictionary = read_dictionary
if new_dictionary[“plane_2_bought”] == true:
new_dictionary[“plane_equipped”] = 2
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_2_button.text = “Equipped”
elif new_dictionary[“coins”] >= 2000:
global.button_click_sound.play()
new_dictionary[“coins”] -= 2000
new_dictionary[“plane_2_bought”] = true
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_2_button.text = “Equip”
else:
print(“insufficient coins”)
global.no_click_sound.play()

func _on_BuyPlane3_button_up():
var read_dictionary = str2var(change_file().get_as_text())
var new_dictionary = read_dictionary
if new_dictionary[“plane_3_bought”] == true:
new_dictionary[“plane_equipped”] = 3
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_3_button.text = “Equipped”
elif new_dictionary[“coins”] >= 3000:
global.button_click_sound.play()
new_dictionary[“coins”] -= 3000
new_dictionary[“plane_3_bought”] = true
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_3_button.text = “Equip”
else:
print(“insufficient coins”)
global.no_click_sound.play()

func _on_BuyPlane4_button_up():
var read_dictionary = str2var(change_file().get_as_text())
var new_dictionary = read_dictionary
if new_dictionary[“plane_4_bought”] == true:
new_dictionary[“plane_equipped”] = 4
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_4_button.text = “Equipped”
elif new_dictionary[“coins”] >= 4269:
global.button_click_sound.play()
new_dictionary[“coins”] -= 4269
new_dictionary[“plane_4_bought”] = true
change_file().store_string(var2str(new_dictionary))
change_file().close()
plane_4_button.text = “Equip”
else:
print(“insufficient coins”)
global.no_click_sound.play()

func _on_Back_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/Shop.tscn”)

func _on_DefaultPlaneButton_button_up():
global.no_click_sound.play()
var read_dictionary = str2var(change_file().get_as_text())
var new_dictionary = read_dictionary
new_dictionary[“plane_equipped”] = 0
change_file().store_string(var2str(new_dictionary))
change_file().close()
change_file().close()
default_plane_button.text = “Equipped”

func change_file():
var file = File.new()
var err = file.open(global.SAVE_FILE, File.READ_WRITE)
if err == OK:
return file
print(“open file success”)
else:
print("error opening file, error: ", err)
func _on_NextButton_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane2.tscn”)

func _on_BackButton_pressed():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane1.tscn”)

func _on_NextButton1_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane3.tscn”)

func _on_NextButton23_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane.tscn”)

func _on_BackButton232_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane.tscn”)

func _on_BackButton321312_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane2.tscn”)

func _on_NextButton23123_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane4.tscn”)

func _on_BackButton2212412_button_up():
global.button_click_sound.play()
get_tree().change_scene(“res://Assets/Room/ShopPlane3.tscn”)

`
:bust_in_silhouette: Reply From: Juxxec

The change_scene method returns a value. Can you print what that value is and share it with us here?

I think this is it: e 0:00:03.465 get_node: (node not found: “buyplane2” (relative to “/root/planeshopdefault”).) <c++ error> method failed. returning: nullptr <c++ source> scene/main/node.cpp:1465 @ get_node() shopplane.gd:4 @ _ready()
I get the error for buyplane1,2,3,4 buyplane1 ,2,3,4 are in a different scene.Maybe that’s why but i can’t figure out how to fix it

BainBan | 2022-12-02 17:47

:bust_in_silhouette: Reply From: Gluon

In that case it is likely that the scene doesnt exist or the scene is not in the location you are pointing too. For example you have get_tree().change_scene("res://Assets/Room/Shop.tscn")but if the scene was moved at some point and is now at another location in your file structure then the system would not be able to switch too it.

I would suggest you go through and double check all of your scenes locations.

Thanks, I will see if it works. But get_tree().change_scene() auto completed the path for me

BainBan | 2022-12-03 06:21

Regardless, maybe you move the scene at some point. Can you check if your scene is located at res://Assets/Room/ShopPlane4.tscn ?

Can you share your whole project? It doesn’t seem to be an issue with the change_scene method persay, as it might somethinig in the scene that has moved. If you notice the error message node not found: "buyplane2". The node buyplane2 is somewhere inside your ShopPlane2 scene, right?

Juxxec | 2022-12-03 11:22