#Trying to save/load a resource, get parser error class

6 messages · Page 1 of 1 (latest)

desert totem
#

Hey! I just finished M8 from the GDquest 2D Module and now I am trying to make a simple clicker/idle game, mostly just as a learning experience.
I am trying to learn how to save/load resources, because a clicker game where you can't save your progress is probably pretty bad. I orientated my approach on this video https://youtu.be/wSq1QJ-g91M?si=HbwSQRz38LGyFiRG .

The actual problem:
I get the error: 'Parser error class "BurritoStats" hides a global script class', only when I'm trying to run the game.

My assumption is that I am not allowed to give the BurritoStats script a class name cause for some reason it interferes with the saving/loading of the created resources?

I am not sure what you need to help me, so I just share all my code so far.
I have 2 Resource scripts which are:

extends Resource

# Burrito amount variables
@export var burrito_amount: float = 0.0

# Money variables
@export var burrito_dollar_value: float = 1.0
@export var burrito_dollar: float = 1.0```

and

```class_name BurritoSaveData
extends BurritoStats

@export var stats: Array[BurritoStats] = []```

Then I have a SaverLoader script which is applied to an utility node in the main theme. It looks like this (the buttons are connected):
```class_name SaverLoader
extends Node

const SAVE_GAME_PATH := "res://Save Games/savegame.tres"

@export var burritostats_save: Resource

func write_savegame() -> void:
    ResourceSaver.save(burritostats_save, SAVE_GAME_PATH ,1)

func load_savegame() -> Resource:
    if ResourceLoader.exists(SAVE_GAME_PATH):
        return load(SAVE_GAME_PATH)
    return null
    
func button_save()-> void:
    write_savegame()
    
func button_load() -> void:
    load_savegame()```

And lastly the script to run the actual game which is attached to a GameManager node:
```extends Node

# Loading essential nodes
@onready var burrito_button = %BurritoButton
@onready var burrito_counter = %BurritoCounter
@onready var dollar_counter = %DollarCounter
@onready var cpu_particles_2d = %CPUParticles2D

# Burrito amount variables
# Loading Burrito Stats Resources
@export var all_stats: Array[BurritoSaveData] = []:
    set = set_all_stats

## Saving and loading Burrito Stats from Resources "BurritoStats.gd" 
@onready var saver_loader = %SaverLoader
## Index for which resource savedata from the Array gets loaded.
@export var save_data_idx := 0

## Setter for the parem all stats resource BurritoSaveData.
## Make sure to set the last saved entry from SaverLoader or creates a new Resource.
func set_all_stats(current_all_stats: Array[BurritoSaveData]) -> void:
    if all_stats == null:
        current_all_stats[0] = BurritoSaveData.new()
    all_stats = current_all_stats

func _ready() -> void:
    # Connecting Burrito Button with clickcounter funtion
    burrito_button.pressed.connect(clickcounter)
    
# Function for pressing burrito button
func clickcounter() -> void:
    # Creating an array variable for the saved data loaded.
    var save_data_stats := all_stats[save_data_idx]
    # Increase BurritoCounter amount per click +1
    save_data_stats.burrito_amount += 1
    # Calculate money earned with burritos
    var burrito_dollar_amount : float 
    burrito_dollar_amount = save_data_stats.burrito_amount * save_data_stats.burrito_dollar_value```

Thankful for any help 🙏
cinder ore
#

Do you have any globals/autoloads in the project? If one of them is named BurritoStats you'll have to just not give that global a class name.

desert totem
#

In case I can't figure it out I will try to redo the whole thing in a new project tomorrow and see if I get the same error. Maybe I just did smth weird with idk saving the files or smth without noticing.

mild beacon
#

I'd ask the same thing as eerywax, check your project/autoload configuration, maybe you have an autoload there that is causing the issue.

desert totem