Trying to save "Diaries" (Collectables)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Maulve

Good day. I’m trying to make “Diaries” you can collect in a game. Just little Texts basically.
However, I’ve been running into some issues trying to “Collect” said Diaries.
This is actually my second attempt trying to do this, as the first had too many issues that I wasn’t able to track down.

extends Resource
class_name Saves

# for now testing with 4 Diaries
export(Array)var Diaries = [false, false, false, false]

This is the backbone of this, holding the “Diaries” Array to store which Diaries
you’ve collected. Later it will also be used to store and save other data.

extends Saves
class_name DiaryBase

# for testing
func _ready():

func DiaryCollect(Diary):
    # gets correct Position in the Array
    var Arraypos = Diary - 1
    Saves.Diaries[Arraypos] = true

This contains the function DiaryCollect(Diary). Which will be called once the player collects a Diary. (Diary) is just the number of the Diary. Arraypos will be the actual position in the Array, as an Array starts with 0.

extends LevelBase

var DiaryBase = preload("res://src/Resources/")

func _ready():

LevelBase is currently just an empty script, will be used later. I tried to preload DiaryBase and use the _ready() function in to simulate collecting a Diary, however it didn’t work.

I am very desperate to finally get some help on this. I’ve tried using a static function in - but I need the Diaries variable in there.
I’ve tried Autoloading to access it easier - but it didn’t work as I intented.
I’ve looked all around for already existing help - yet found nothing useful.

If any additional Info is required, I’m more than willing to provide it.
Thank you for reading, and also thanks in advance for potentially helping.

BTW, I am a beginner with Godot and much of Game Developing and Coding in general.

:bust_in_silhouette: Reply From: the_maven

Sorry if I am wrong, but I think your problem is programming related.

Try this:

What you said is related to those:
Chapter 2 – Flow Control;
Chapter 3 – Functions;
Chapter 4 – Lists;
and Chapter 5 – Dictionaries and Structuring Data.

I would suggest you read the full book from the beginning.

And I also think dictionary data type would be more useful instead of array. And flow control code.

(sorry for late response, I was on vacation)

Thank you! I’ll read through it and try to fix this up.

Maulve | 2022-10-03 18:08