0 votes

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.

Saves.gd

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.

DiaryBase.gd

extends Saves
class_name DiaryBase

# for testing
func _ready():
    DiaryCollect(1)

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

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.

Tutorial.gd

extends LevelBase

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

func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)

LevelBase is currently just an empty script, will be used later. I tried to preload DiaryBase and use the _ready() function in *DiaryBase.gd* 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 DiaryBase.gd - but I need the Diaries variable in there.
I've tried Autoloading Saves.gd 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.

Godot version 3.5.1.stable
in Engine by (12 points)

1 Answer

0 votes

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

Try this:
https://automatetheboringstuff.com/

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.

by (232 points)

(sorry for late response, I was on vacation)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.