Search code examples
c++yamlyaml-cpp

Reading maps in yaml-cpp


I have the following yaml file:

Pantalla:
ancho: 640
alto: 480

Configuracion:
    vel_personaje: 3
    merge_scroll: 30

Tipos:
    - nombre: arbol
      imagen: img/tree
      ancho_base: 2
      alto_base: 2
      pixel_ref_x: 30
      pixel_ref_y: 40
      fps: 10
      delay: 5

    - nombre: casa
      imagen: img/house

    - nombre: auto
      imagen: img/car
      ancho_base: 5
      alto_base: 5

Escenario:
    - nombre: principal
      size_x: 100
      size_y: 100
      entidades:  
           ­- {x: 10, y: 15, tipo: tierra}
           ­- {x: 15, y: 20, tipo: tierra}
           ­- {x: 10, y: 15, tipo: agua} 
         ­  - {x: 30, y: 55, tipo: castillo}
    protagonista:
        - tipo: principal
          x: 50
          y: 50

When I tried to read the different "entidades", the yaml-cpp says the following:

terminate called after throwing an instance of 'YAML::ParserException' what(): yaml-cpp: error at line 32, column 25: illegal map value

Line 32 column 25 is just after "y: ". I don't know that I'm doing wrong. Thanks for the help!


Solution

  • The dash in line 28 is \u00ad, which is "soft hyphen". I think it should be like this:

    Escenario:
        nombre: principal
        size_x: 100
        size_y: 100
        entidades:  
            ­- {x: 10, y: 15, tipo: tierra}
        ­    - {x: 15, y: 20, tipo: tierra}
        ­    - {x: 10, y: 15, tipo: agua}
        ­    - {x: 30, y: 55, tipo: castillo}
        protagonista:
            - tipo: principal
              x: 50
              y: 50
              y: 50