So I have a little warning screen for my game, and the script for that scene holds the instructions for saving and loading your file. The thing about it is, despite the fact that I only saved two variables into the save file and also made it so that the save-dependent moments only occur in this particular scene, for reasons unbeknownst to me it applies to every scene in the game. I can open a completely unrelated scene and have it automatically perform the save-dependent actions. I've tried everything I could think of and I feel like a need some help with this.
#Script holding the save file applies to all scenes
1 messages · Page 1 of 1 (latest)
@onready var altpressed = false
@onready var f4pressed = false
@onready var jesus = $"altf4detection"
@onready var integrity = false
@onready var scenename: String = "warning"
@onready var ignored = false
var save_path = "user://i sure hope this works if not i will i dont even know anymore man.save"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if scenename == "warning":
integrity = false
load_your_shit()
if integrity == true:
if scenename == "warning":
get_tree().change_scene_to_file("res://scenes/heaven.tscn")
if ignored == true:
if scenename == "warning":
get_tree().change_scene_to_file("res://scenes/new main menu.tscn")
func _input(ev):
if Input.is_action_just_pressed("big select"):
if scenename == "warning":
get_tree().change_scene_to_file("res://scenes/new main menu.tscn")
ignored = true
save()
if Input.is_action_pressed("alt"):
altpressed = true
save()
if Input.is_action_pressed("f4"):
integrity = true
save()
if Input.is_action_just_released("alt"):
altpressed = false
save()
else:
pass
func _on_timer_timeout() -> void:
$"space".play("activated")
func save():
if scenename == "warning":
var files = FileAccess.open(save_path, FileAccess.WRITE)
files.store_var(integrity)
files.store_var(ignored)
func load_your_shit():
if scenename == "warning":
if FileAccess.file_exists(save_path):
var files = FileAccess.open(save_path, FileAccess.READ)
integrity = files.get_var(integrity)
ignored = files.get_var(ignored)
else:
print("well shit")
integrity = false
ignored = false
If your goal was to have it only save if the scenename is warning, then it will always do so because it is literally the default value.
You'd need whatever creates this node to set it to something else.
btw, is this an Autoload?
Yes, it is an autoload
That explains why it runs despite the script being nowhere in sight I'm assuming