The function spawn_link/1
takes a function as an argument. But in your code you dont pass a function into it:
start_server() ->
spawn_link(game_loop(0,0)).
That sample means that the function game_loop/2
will be called first and after it returns spawn_link/1
will be called with an argument which is a result of calling of game_loop/2
. But your function game_loop/2
implements infinite loop so it will never returns and so spawn_link/1
will never be called. If we even assume that game_loop/2
returns it must return a function to call spawn_link/1
properly, otherwise an exception will rise.
To do what you want you should pass game_loop/2
as a function into spawn_link/1
:
start_server() ->
spawn_link(fun () -> game_loop(0,0) end).