The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I seem to be doing something wrong when I append an Entry into the Array.

I'm expecting an Array of Entry objects that I can then sort using a custom sort function.

extends Panel


var month: Month
var entries_array: Array = []


onready var ViewEntry = load("res://views/ViewEntry.tscn")
onready var vbox_entries: VBoxContainer = $ScrollContainer/VBoxEntries


func insert_entry(new_entry: Entry) -> void:

    print("New Entry")
    print(new_entry.to_string())

    print("Pre Append...")
    for entry in entries_array:
        print(entry.to_string())

    entries_array.append(new_entry)

    print("Post Append...")
    for entry in entries_array:
        print(entry.to_string())

Produces the following output:

New Entry
1 January 2020 Outgoing: £10 1/1/2020 10
Pre Append...
Post Append...
1 January 2020 Outgoing: £10 1/1/2020 10
New Entry
2 January 2020 Outgoing: £20 2/1/2020 20
Pre Append...
2 January 2020 Outgoing: £20 2/1/2020 20
Post Append...
2 January 2020 Outgoing: £20 2/1/2020 20
2 January 2020 Outgoing: £20 2/1/2020 20

in Engine by (12 points)

The issue is likely with how you call Insert_entry (a part that you omitted) , how Entry is defined (a part that you omitted as well) or what your to_string-method returns (which again you omitted). Please provide all relevant code.

The code you provided looks fine and shouldn't produce an issue.

I finally tracked down the issue myself.

It has nothing to do with storing the Entry objects into an Array and everything to do with how Entry is defined, as you point out.

I didn't account for Objects being passed as references, so the passed Entry objects all refer (further back in the code) to the same initial Entry object... doh!

What is the etiquette for answering ones own asked question on this board?

Please log in or register to answer this question.

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.