Question
why is it printing the points instead of the beaten_levels variable?
extends Button
var save_path = "user://skibidi.save"
var points = 67
var current_level = 0
var beaten_levels = [false, false, false, false, false]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func _on_pressed() -> void:
$"../../../../HurtDeath".play()
get_tree().change_scene_to_file("res://scenes/UI/Level Select.tscn")
self.disabled = true
func _on_button_2_pressed() -> void:
$"../../../../HurtDeath2".play()
var file = FileAccess.open(save_path, FileAccess.WRITE)
file.store_var(points)
file.store_var(current_level)
file.store_var(beaten_levels)
file.close()
var file2 = FileAccess.open(save_path, FileAccess.READ)
current_level = file2.get_var()
print(current_level)
get_tree().change_scene_to_file("res://scenes/UI/Level Select.tscn")
I’ve just checked the doc real fast and from that, order is important. EDIT: It’s a FIFO (First In, First Out) The first “get” will return the first variable saved. [Previously wrong = FILO (First In, Last Out). The first “get” will give you the last entered var.]
That’s why.
And, since you don’t force your variables to a certain type, they are defined as Variant, thus any assignment will work without error.
I.E.:
var current_level := 0
or its variant
var current_level : int = 0
would give an error with your code above since you would be trying to get current_level (an int) a value of array.
EDIT: As this has been tagged as the Solution, I’ve edited the post to reflects the save. It’s FIFO, not LIFO.
wait, i ment current_level. Sorry
Yeah, it’s printing the points instead of the current level
Your variable name is of no consequence to GODOT. The function will return what has been saved.
As I said, it was a quick read. Instead of LIFO it might be FIFO (First In, First Out), so it would be “points” returned first, then “current_level” and finally “beaten_levels”.
file.store_var(current_level)
file.store_var(points)
file.store_var(beaten_levels)
it worked
Thank you for the support!
One more thing:
How come the points here now trying to equal the beaten levels? I changed it so it was beaten levels instead of current levels.
extends Control
var current_level = 1
var current = 0
var unfinished = 1
@export var world_1 = ["one", "too", "thriii", "for", "fyve"]
var world_2 = ["Sigma", "too", "thriii", "for", "fyve"]
@export var world_2_links = ["res://scenes/levels/First Level.tscn", "res://scenes/levels/First Level.tscn", "res://scenes/levels/First Level.tscn", "res://scenes/levels/First Level.tscn", "res://scenes/levels/First Level.tscn"]
var save_path = "user://skibidi.save"
var save_path2 = "user://skibido.save"
var points = 0
var current_world = [0, 2, 3 , 1, "0h10"]
var current_world_link = [1, 1]# Called when the node enters the scene tree for the first time.
var land_list = [world_1, world_2]
var beaten_levels = [false, false, false, true, false]
var levels_done = ["him", "she", "her", "new"]
@export var world_index = 1
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var file = FileAccess.open(save_path, FileAccess.READ)
current_level = points
points = file.get_var(points)
$Label3.text = str(points)
print(levels_done)
file.close()
$Label2.text = str(world_index)