Godot Version
V4.5
Question
Hey, can anyone please tell me why the beaten_levels variable wont work showing off the save file version?
extends CharacterBody2D
const CharacterBody2d = preload(“res://scenes/character_body_2d.gd”)
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
var flip_gravity = false
var JUMPS = 2
var SPEED = 100.0
var JUMP_VELOCITY = -150.0
var ChuRub: bool = false
var powerup = preload(“res://scenes/bullets/Boomer.tscn”)
var max_health = 100
var health = max_health
var attack = 10
var hurt = 10
var bounce_boost = 2
@onready var churub_0001: Sprite2D = %“Churub-0001”
var in_water = false
var character_type = 4
var current_item = 0
var full_health_boss = 100
var boss_health = 100
var target : String = “ggg”
var canshoot = true
var save_path = “user://skibidi.save”
var points = 1
var beaten_levels = 0
var current_level = 0
var world_index = 0
var unfinished = [false, true]
func _ready() → void:
var file = FileAccess.open(save_path, FileAccess.READ)
points = file.get_var(points)
current_level = file.get_var(current_level)
world_index = file.get_var(world_index)
unfinished = file.get_var(unfinished)
beaten_levels = file.get_var(beaten_levels)
print(beaten_levels)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(unfinished)
print(unfinished)
print(unfinished)
print(unfinished)
print(beaten_levels)
get_var doesn’t take an argument like you think, do not supply an argument to it.
beaten_levels = file.get_var() # empty parenthesis, no args
Are you sure your save file exists and has data?
Make sure to format code pastes
Posting here so to be linked for later use instead of re-typing this every time
Make sure you paste scripts instead of screenshots. To properly format pasted code use three ticks ``` at the start and end of your paste like so:
```
# type or paste code here
func _ready() -> void:
print("My ready function!")
```
Results in:
# type or paste code here
func _ready() -> void:
print("My ready function!")
Press the </> button or ctrl+e in the forum to create these ticks.
[2024-09-02…
1 Like
Wait, but now it just prints it as a one
extends CharacterBody2D
const CharacterBody2d = preload("res://scenes/character_body_2d.gd")
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
var flip_gravity = false
var JUMPS = 2
var SPEED = 100.0
var JUMP_VELOCITY = -150.0
var ChuRub: bool = false
var powerup = preload("res://scenes/bullets/Boomer.tscn")
var max_health = 100
var health = max_health
var attack = 10
var hurt = 10
var bounce_boost = 2
@onready var churub_0001: Sprite2D = %"Churub-0001"
var in_water = false
var character_type = 4
var current_item = 0
var full_health_boss = 100
var boss_health = 100
var target : String = "ggg"
var canshoot = true
var save_path = "user://skibidi.save"
var points = 1
var beaten_levels = [false, false, false, false, false]
var current_level = 0
var world_index = 0
var unfinished = 0
func _ready() -> void:
var file = FileAccess.open(save_path, FileAccess.READ)
points = file.get_var(points)
current_level = file.get_var(current_level)
world_index = file.get_var(world_index)
unfinished = file.get_var(unfinished)
beaten_levels = file.get_var()
points = beaten_levels
print(beaten_levels)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(world_index)
print(unfinished)
print(unfinished)
print(unfinished)
print(unfinished)
print(beaten_levels)
Because then I could see witch section was the world index
And I don’t know why, but the beaten levels variable will be a number, not an array for some reason.
How? Is world_index somehow changed between two consecutive prints?
So then why print the same thing many times in a row?
wait, what was I thinking?
Sorry bout that
I have a strange solution:
Instead of an array, it’s just a number.
1=true
0=false
these are the levels beaten:
0000
Why do you still send arguments to get_var()? It requires no arguments as it was already pointed out by @gertkeno
it has no argument in beaten levels in the get_var(), but that still doesn’t fix anything. It’s still getting me no array back.
Have you put an array in?
There’s no any store_var() calls in the code you posted.
Here, got this: they all gone now.
Your welcome. I think I’m just going now.