This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello friends, how can I save several positions of different objects in the same dictionary?
I want to save the position and a variable of a music game note together with the other potions of the other notes but I cannot do it
Or I would also like to do something like a print but the print saturates me and it only prints 20 lines
I would like to be able to do the print thing but save it in a text or something to do

var pos = Vector2()
var color = 1
onready var n = preload("res//:rut_of_note.tscn")

func _ready():  
var note = n.instance()
pos = global_position
color = 1

print("note.position =",pos)
print("note.color =",color)
print("get_parent().add_child(note)")
Godot version Godot 3.4 Stable
in Engine by (17 points)

I don't know how I can help you with saving the positions of objects to a dictionary. But if you want to see the positions (along with other information) for nodes, try looking on the "Remote" tab in the scene tree while the game is running. The "Remote" tab shows the scene tree of the currently running game. Click on one of the nodes, and the information for the node will appear in the Inspector.

1 Answer

0 votes

Since you will be dealing with multiple objects then nested dictionaries are best used for your purposes.

var notes = Dictionary()
onready var n = preload("res//:rut_of_note.tscn")

func _ready():  
    var note = Dictionary()
    note.instance = n.instance()
    note.color = 1

    #instance has to be part of the scentree to get its position
    get_parent().add_child(note.instance)
    note.pos = note.instance.global_position

    #add note to notes dictionary using its instance id as reference
    notes[str(note.instance.get_instance_id())] = note

You can print the notes dictionary as a whole

print(notes)

Or with line formatting

for _note in notes:
    print(_note)

Or the way you had it before

for _note in notes:
    print(_note.instance)
    print("note.position =", _note.pos)
    print("note.color =", _note.color)
by (6,942 points)
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.