Records pattern matching in Erlang

Viewed 1978

For fun i am trying to recreate one of my favorite boardgames in Erlang and I am trying pattern match a nested record and I always get the error msg no matter what I try:

** exception error: no function clause matching 
                kingoftokyo_server:add_player("john",
                  {gamestate,[],[],[],[]}) (kingoftokyo_server.erl, line 40)

my code looks like this:

 -record(player,{playerName,cards,energy}).
 -record(board,{city_center,outside}).
 -record(gamestate,{board,player,dices,game_round}).

 add_player(Name,{Board,{PlayerName,Cards,Energy},Dices,Game_round}) ->
    NewList = lists:append(Name, PlayerName),
    NewState = {Board,{NewList,Cards,Energy},Dices,Game_round},
    NewState.

I dont see why the clause does not match in the add_player function. I have tried all I could find but don't get why this does not work.

Any pointers would be greatly appreciated!

1 Answers
Related