# How to write code at server side in nakama

**URL:** https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887
**Category:** Game Design
**Created:** [August 5, 2020, 5:41am UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887 "2020-08-05T05:41:50Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![kmsudhir](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kmsudhir](https://forum.heroiclabs.com/u/kmsudhir)
#### Post date: [August 5, 2020, 5:41am UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/1 "2020-08-05T05:41:50Z")

</div>

I am new in nakama just started working on nakama. i have run nakama server using docker-compose but i did not know to to code at server for nakama.

---

<div class="post-metadata">

### Author: ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)
#### Post date: [August 5, 2020, 9:06am UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/2 "2020-08-05T09:06:00Z")

</div>

@kmsudhir It’s great you’re able to start and run the server with local development. The next steps before you start to write code with the server framework is usually to integrate one of our client sdks with your project but I can walk you through the “hello world” with the server framework and then share some links to help you learn other parts of the server functions you can write and call for your game logic.

1. To start with lets check the layout of your project. You’ll want to have a code structure that looks like:

2. Inside your Docker compose file you’ll want to update the path you’ll use within the server to read Lua modules to look like:

3. Your “main.lua” file will have a very simple bit of logic to show that the server has loaded and executed the script:

If everything is set up correctly you’ll see “Hello World” printed to the console when you run the server. Hope that helps.

---

<div class="post-metadata">

### Author: ![kmsudhir](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kmsudhir](https://forum.heroiclabs.com/u/kmsudhir)
#### Post date: [August 5, 2020, 12:56pm UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/3 "2020-08-05T12:56:47Z")

</div>

I have done this part and want next move and to create user from client site. how to write code for this functionality

---

<div class="post-metadata">

### Author: ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)
#### Post date: [August 7, 2020, 9:08am UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/4 "2020-08-07T09:08:40Z")

</div>

@kmsudhir There’s resources on the documentation for how to do this:

[https://heroiclabs.com/docs/authentication/](https://heroiclabs.com/docs/authentication/)  
and  
[https://heroiclabs.com/docs/user-accounts/](https://heroiclabs.com/docs/user-accounts/)

You should also download and unpack the client SDK based on which game engine or programming language you’re going to use for your project. There’s introductory guides for each of the client SDKs also on the docs.

---

<div class="post-metadata">

### Author: ![kmsudhir](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kmsudhir](https://forum.heroiclabs.com/u/kmsudhir)
#### Post date: [August 10, 2020, 2:47am UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/5 "2020-08-10T02:47:25Z")

</div>

I have download nakama open source code from [https://github.com/heroiclabs/nakama](https://github.com/heroiclabs/nakama) and now want to modify according to me.

Now please suggest where to write my own code with nakama open source code. because i am little bit confuse with new code that how it will run with nakama open source code.

---

<div class="post-metadata">

### Author: ![Mohammed](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@Mohammed](https://forum.heroiclabs.com/u/Mohammed)
#### Post date: [August 12, 2020, 5:35pm UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/6 "2020-08-12T17:35:06Z")

</div>

For me I am using  
**MacOS** and **Nakama:2.7.0** and my game engine is **Unity**

There are two languages supported by Nakama for now  
Lua & Go , if you don’t know any of them I suggest you to start with lua language (my opinion as it is easier )

Now I really dont understand what do you mean by "suggest where to write my own code " but I think you are confused where you add you Lua files. My files structure looks like this

```auto
├
├── docker-compose.yml
└── nakama / data / modules (I keep all my .lua files here)

```

Now you can add a file like this my\_rpc\_calls.lua

The file contains this

```auto
local nk = require("nakama")

local function getservertime(context, payload)
    local resp = {
        current_time = os.time()
    }
    return nk.json_encode(resp)
end

nk.register_rpc(getservertime,"GetServerTime")

```

Now from client side, Lets say you are using unity

```auto
Task<IApiRpc> searchTask = _client.RpcAsync(Session,"GetServerTime");
IApiRpc Result = await searchTask;
print("Payload = "+Result.Payload);

```

If you are taking this seriously you should read the documentation (at least skim through it and read more about the things you need)

check [https://github.com/heroiclabs/unity-sampleproject](https://github.com/heroiclabs/unity-sampleproject) It is very useful to learn lua by example and unity engine and how they are integrated.

the forum is very useful skim through the questions and answers there is always something new to learn

---

<div class="post-metadata">

### Author: ![kmsudhir](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kmsudhir](https://forum.heroiclabs.com/u/kmsudhir)
#### Post date: [August 16, 2020, 3:40pm UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/7 "2020-08-16T15:40:44Z")

</div>

local nk = require(“nakama”)

local function getservertime(context, payload)  
local resp = {  
current\_time = os.time()  
}  
return nk.json\_encode(resp)  
end

nk.register\_rpc(getservertime,“GetServerTime”)

i have written same code in nakama and start nakama server but in unity not getting response then

how to test above function at server side that function working or not.

---

<div class="post-metadata">

### Author: ![Mohammed](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@Mohammed](https://forum.heroiclabs.com/u/Mohammed)
#### Post date: [August 16, 2020, 6:00pm UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/8 "2020-08-16T18:00:41Z")

</div>

> [@Mohammed](#):
>
> ```auto
> Task<IApiRpc> searchTask = _client.RpcAsync(Session,"GetServerTime");
> IApiRpc Result = await searchTask;
> print("Payload = "+Result.Payload);
> 
> ```

Use this code in unity

---

<div class="post-metadata">

### Author: ![Mohammed](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@Mohammed](https://forum.heroiclabs.com/u/Mohammed)
#### Post date: [August 16, 2020, 6:05pm UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/9 "2020-08-16T18:05:05Z")

</div>

I recommend that you download [https://github.com/heroiclabs/unity-sampleproject](https://github.com/heroiclabs/unity-sampleproject) and start it. Then you can check the code how they handle authentication / adding friend / calling RPC and more … basically you will get what need to get to the point where things make sense to you.

---

<div class="post-metadata">

### Author: ![kmsudhir](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kmsudhir](https://forum.heroiclabs.com/u/kmsudhir)
#### Post date: [August 17, 2020, 5:24pm UTC](https://forum.heroiclabs.com/t/how-to-write-code-at-server-side-in-nakama/887/10 "2020-08-17T17:24:24Z")

</div>

I am getting error RPC function not found

{“error”:“RPC function not found”,“message”:“RPC function not found”,“code”:5}
