Struct (KeyError) key :decription not found

Hello everyone,

I’m a newbie to Elixir and reading the book “Learn Functional Programming with Elixir”.

In the book this stuctured was defined:

defmodule DungeonCrawl.Character do
  defstruct name: nil,
            description: nil,
            hit_points: 0,
            max_hit_points: 0,
            attack_description: nil,
            damage_range: nil

and initialized here:

defmodule DungeonCrawl.Heroes do
  alias DungeonCrawl.Character

 def all do
        name: "Knight",
        decription: "Knight has strong defense and consistent damage.",
        hitpoints: 18,
        max_hit_points: 18,
        damage_range: 4..5,
        attack_description: "a sword"

Without the Heroes module, compile is ok. With the Heroes module, I get this error:

== Compilation error in file lib/dungeon_crawl/heroes.ex ==
** (KeyError) key :decription not found
    (dungeon_crawl 0.1.0) expanding struct: DungeonCrawl.Character.__struct__/1
    (dungeon_crawl 0.1.0) lib/dungeon_crawl/heroes.ex:6: DungeonCrawl.Heroes.all/0
    (elixir 1.11.1) lib/kernel/parallel_compiler.ex:314: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

I’ve been trying to fix this forever. The code seems ok. Please help.

You have a small typo, the struct field is description, but you tried to use decription :grin:

1 Like

Thanks, I just corrected the typo, but that didn’t fix the problem. See the attached image, there is a red highlight on Character


What is the error now?

Edit: Also hit_points vs. hitpoints.

1 Like

In your DungeonCrawl.Character it is declared as hit_points but your trying to use it in DungeonCrawl.Heroes as hitpoints

1 Like

Wow!. That was it. Thank you.