How do we store data structures for a game server?

I’ve been using the Crystal language now and it’s been amazing. However, Elixir looked realy enticing but I don’t understand how to store user data. For example, if a user connects through a TCP Server socket connection. I want to authenticate them, and then store their rpg user data values in a class. However, Elixir is a functional programming language and this paradigm is brand new to me :stuck_out_tongue:

So what’s the equivalent of let’s say:

class Player
property level = 0
property char_name = "Player #1"  

new_player =

in Elixir? Are there classes? Couldn’t find anything in the docs, thanks!

Sorry, no classes, no mutability

That could be

defmodule Game do
  defstruct(level: 0, char_name: "")
  def new(initial_state \\ []), 
    do: struct(%Game{}, initial_state)

In console

iex> koko = level: 1, char_name: "koko"
%Game{char_name: "koko", level: 1}

But remember You get only an immutable data structure in return. You will need to put structure’s manipulation functions inside a module.


Wow, that was a fast response! Thanks a lot. Yeah, this seems like a whole new ball game to me, going to have to read up about functional programming some more. Have been watching the Elixir tutorials however

1 Like

You are welcome :slight_smile: