The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes
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")

```
`
in Engine by (14 points)

2 Answers

0 votes

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

by (294 points)

I think this is it: e 0:00:03.465 getnode: (node not found: "buyplane2" (relative to "/root/planeshopdefault").) <c++ error> method failed. returning: nullptr <c++ source> scene/main/node.cpp:1465 @ getnode() 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

0 votes

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.

by (3,328 points)

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

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?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.