Godot Version
4.3
Question
whenever i load a certain scene, it repeatedly reloads over and over, not allowing me press any buttons.
P.S. im not pausing the tree
4.3
whenever i load a certain scene, it repeatedly reloads over and over, not allowing me press any buttons.
P.S. im not pausing the tree
Can you paste your script
extends Control
var scene = preload("res://Scenes/restart_menu.tscn")
var Money = 2
var Seeds_Payment = 4
var Seeds = 0
var SeedsPrice = 2
func _on_plant_seed_pressed() -> void:
if Map.Seeds >= 0:
Map.Seeds -= 1
Map.Money += Seeds_Payment
else:
pass
func _process(delta: float) -> void:
if Map.Money <= -1:
get_tree().paused = false
get_tree().change_scene_to_file("res://Scenes/restart_menu.tscn")
func _on_buy_seeds_pressed() -> void:
Map.Money -= Map.SeedsPrice
Map.Seeds += 1
func _ready() -> void:
pass
func save():
var save_dict = {
"Money" : Money,
"Seeds Payment" : Seeds_Payment,
"Seeds" : SeedsPrice,
"Seed Price" : SeedsPrice
}
return save_dict
func save_game():
var savegame = FileAccess.open_encrypted_with_pass("user://savegame.save", FileAccess.WRITE, "1606")
var json_string = JSON.stringify(save())
savegame.store_line(json_string)
func load_data():
if not FileAccess.file_exists("user://savegame.save"):
return
var savegame = FileAccess.open_encrypted_with_pass("user://savegame.save", FileAccess.READ, "1606")
while savegame.get_position() < savegame.get_length():
var json_string = save_game().getline()
var json = JSON.new()
var parse_result = json.parse(json_string)
var node_data = json.get_data()
print(node_data)
func _on_save_pressed() -> void:
save_game()
func _on_load_pressed() -> void:
load_
this is the script that loads it
Seems like the autoload Map
needs to reset it Money
to more than 0 before this scene can start again.
Make sure to paste between three ticks
i have that in my script already, but it doesnt work
Could you paste the script that resets Map.Money
? I notice you have a variable named Money
, but it’s not the same and seems only used for saving the number 2? Do you believe Map.Money
and Money
are the same?
i used different one because it wouldnt work for some odd reason
but the variable is in the script
If this is the only script, is it in Globals project settings and also in the scene tree? That will make two seperate versions, where one is Map.Money
and the other local version is Money
where Map.Money
is accessable anywhere and Money
stays 2 forever.
Yes, does that affect it?
Yes it is bad to have two instances of this script in different contexts and expect them to work the same. You have a largely inaccessable version changing scenes, I am sure this is the root of your issue.
Ok, i will change it when i get home. Thanks for your help!