Attention | Topic was automatically imported from the old Question2Answer platform. | |
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”)
`