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 I have this problem since yesterday, I wanted to generate a list of achievements in the parent scene and update it when loading a reusable scene, inside a for loop
The data is loaded through an autoload(Singleton?) And the data is sent through a signal, obviously I'm doing something wrong but I don't understand what it is or what I'm missing.

lol , I would like to see a list but it doesn't.

Achievement.gd

onready var lista = $Lienzito/AspectRatioContainer/Vertical_list
const logro = preload("res://scenes/Logro.tscn") # Achievement

func _ready():
    # Loop from achievement
    for idx in Config.achievements:
        yield(get_tree(), "idle_frame")
        var logro_extra = logro.instance() # Instance achievement
        #print( Config.achievements[idx]['title'] )
        # add variables from achievement (singleton) expect instance one to one instance ?
        var title = Config.achievements[idx]["title"]
        var image = Config.achievements[idx]["img"]
        var desc = Config.achievements[idx]["desc"]
        # emit_signal to node logro(achievement)
        Config.emit_signal('set_logro', image, title, desc)
        lista.add_child(logro_extra) # add child to Vertical_list

Config.achievement other file from GodotAutoloadSystem

var achievements : Dictionary = {
    0: {
        'title':"Tutorial",
        "desc": "Pasaste el nivel tutorial, donde aprendiste como jugar el juego.",
        "img": "res://assets/achievements/logro1.png"
        },
    1:{
        "title":"x5",
        "desc": "Completaste los primero 5 niveles.",
        "img": "res://assets/achievements/logro5.png"
    },
    2:{
        "title":"25 vidas",
        "desc": "Wow!!! Terminaste los primeros 25 niveles de un solo golpe!",
        "img": "res://assets/achievements/logro_oculto.png"
}

Node to instane

extends Control
func _ready():
    Config.connect("set_logro", self, "_on_set_logro")
func _on_set_logro(img, title, desc):
    $Icono.texture = load(img)
    $Titulo_logro.bbcode_text = title
    $Desc_logro.bbcode_text = desc

my result

thanks in advance

Godot version Godot 3.4.3.stable
in Engine by (20 points)
edited by

logro_extra seems to be the scene you are dynamically creating and is being used to hold acheivement information that should be displayed in a list. It seems your creating and adding the logro_extra scenes to a list, but I don't see where logro_extra is being given any acheivement data. Are you trying to populate logro_extra member data with the call to Config.emit_signal('set_logro', image, title, desc)? If so, I don't think logro_extra will have anything done to it since it hasn't been added to the scene tree yet.

Wow xD, yes, I made the list dynamically and corrected what I was missing, filled in the values ​​of 'each' (lol) instance of "logro_extra" as you inferred before and discarded the code that is too much in the signal and in the node, because it is no longer necessary, it turned out to be something much simpler than I thought, I did more than what has to be done, in the end I finished with this.

extends Node2D

onready var lista = $Lienzito/AspectRatioContainer/Vertical_list
const logro = preload("res://scenes/Logro.tscn") # Achievement

func _ready():
    ## Show achievement list, Muestra la lista de logros
    for idx in Config.achievements:
        var logro_extra = logro.instance() # Instance achievement

        logro_extra.get_node("Icono").texture = load(Config.achievements[idx]["img"])
        logro_extra.get_node("Titulo_logro").bbcode_text = Config.achievements[idx]["title"]
        logro_extra.get_node("Desc_logro").bbcode_text = Config.achievements[idx]["desc"]

        lista.add_child(logro_extra) # add child to Vertical_list

Config.achievement file from GodotAutoloadSystem

var achievements : Dictionary = {
    0: {
        'title':"Tutorial",
        "desc": "Pasaste el nivel tutorial, donde aprendiste como jugar el juego.",
        "img": "res://assets/achievements/logro1.png"
    },
    1:{
        "title":"x5",
        "desc": "Completaste los primero 5 niveles.",
        "img": "res://assets/achievements/logro5.png"
    },
    2:{
        "title":"25 vidas",
        "desc": "Wow!!! Terminaste los primeros 25 niveles de un solo golpe!",
        "img": "res://assets/achievements/logro_oculto.png"
    },
    3: {
        "title":"Gran perdedor x5",
        "desc": "Completa 5 niveles pasandote del limite de puntos recuperando tu puntuacion con los botones circulares.",
        "img": "res://assets/achievements/logro_oculto.png"
    },
    4: {
        "title":"Grandioso perdedor x15",
        "desc": "Completa 15 niveles pasandote del limite de puntos recuperando tu puntuacion con los botones circulares.",
        "img": "res://assets/achievements/logro_oculto.png"
    },
    5: {
        "title":"Perfecto perdedor x25",
        "desc": "Completa 25 niveles pasandote del limite de puntos recuperando tu puntuacion con los botones circulares.",
        "img": "res://assets/achievements/logro_oculto.png"
    },

}

node to instance... nothing.

Result:

Achievevemnts
Thanks a lot. xD

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.