I need help reading hocon configuration lists

Hi, I am having problems reading a list from the configuration. This is my conf file:

interactions {
    example1=[
        {
            questions=[
                "How do i get money?"
                "Does anyone know how to get money?"
                "I need money"
            ]
            answers=[
                "{player} you have to sell in the store"
                "{player} sell items"
            ]
        }
    ]
    example2=[
        {
            questions=[
                "I want to buy a block in the store"
                "I want to go to the store"
                "where do I get blocks"
            ]
            answers=[
                "{player} type /shop"
                "{player} to buy items type /shop"
            ]
        }
    ]
}

And when I try to read what is inside “questions” or “answers” I always get an empty list.
This is the code I am using:

List<String> questions = main.config.node("interactions", key, "questions").childrenList().stream().map(ConfigurationNode::getString).collect(Collectors.toList());
List<String> answers = main.config.node("interactions", key, "answers").childrenList().stream().map(ConfigurationNode::getString).collect(Collectors.toList());

What am I doing wrong? Thanks for reading

example1 is a list - so main.config.node("interactions", key, "questions") is always going to be empty as interactions → example1 → questions is not the same as interactions → example1 (list) → first element → questions.

Is example1, example2 etc. meant to be a list? If so, you need to get main.config.node("interactions", key).childrenList(), then get the questions or answers node from each of those nodes. If not, get rid of the list brackets for example1 and example2.

1 Like

(and you should replace .childrenList().stream().map(ConfigurationNode::getString).collect(Collectors.toList()) with .getList(String.class))

https://configurate.aoeu.xyz/4.1.2/apidocs/org/spongepowered/configurate/ConfigurationNode.html#getList(java.lang.Class)