# Love2D with Nakama

**URL:** <https://forum.heroiclabs.com/t/love2d-with-nakama/2163>\
**Category:** Client Libraries\
**Tags:** getting-started, authentication, lua\
**Created:** [December 6, 2021, 12:35am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163 "2021-12-06T00:35:25Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [December 6, 2021, 12:35am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/1 "2021-12-06T00:35:26Z")

</div>

Hello,

I’m trying do use Nakama with Love2D game engine.  
I read the Lua Client docs but I’m kind of stuck.

I use the last Nakama Server but I got a Unable to login and no new device is visible on my Nakama Console.

```auto
local function device_login(client)
	local body = nakama.create_api_account_device(love2d.uuid())
	local result = nakama.authenticate_device(client, body, true)
    if result then
        if result.token then
            nakama.set_bearer_token(client, result.token)
            return true
        end
    end
	print("Unable to login")
	return false
end

--CORE FUNCTION
function love.load()
    --load nakama
	local config = {
        host = "127.0.0.1",
        port = 7350,
        use_ssl = false,
        username = "defaultkey",
        password = "",
        engine = love2d,
        timeout = 10,
	}
	local client = nakama.create_client(config)

    nakama.sync(function()
        device_login(client)
    end)

```

EDIT! The current output of the authenticate\_device is equal to nil and I still don’t get where to correct this

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)\
**Post date:** [December 6, 2021, 9:29am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/2 "2021-12-06T09:29:31Z")

</div>

Hi @shioridotdev welcome to the forum.

Please can you check that you’re getting a valid value for `body` which you’re passing to the `authenticate_device` function.

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [December 6, 2021, 10:24am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/3 "2021-12-06T10:24:49Z")

</div>

Thanks for the reply,

For the output of the `body` before passing it to the `authenticate_device` it’s

```auto
{ ["id"] = 5c251fc8-5643-4403-c433-04ed336b0dff,}

```

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [December 6, 2021, 6:52pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/4 "2021-12-06T18:52:31Z")

</div>

Here is another output  
As I continue the debugging, seems like I got a little issue with coroutine.

Without coroutine

```auto
init()
authenticate_device() with callback
HTTP POST http://127.0.0.1:7350/v2/account/authenticate/device?create=true&username=shioridotdev
DATA {"id":"dd5cb811-8c7c-4f83-cfbc-04ed336b0dff"}
Unable to login

```

With coroutine

```auto
init()
authenticate_device() with coroutine
HTTP POST http://127.0.0.1:7350/v2/account/authenticate/device?create=true
DATA {"id":"b417483f-bad6-44e9-c413-04ed336b0dff"}

```

EDIT:  
My program doesn’t go inside the fn function in async.lua arround line 12

```auto
	fn(function(...)
		results = { ... }
		if state == "YIELDED" then
			local ok, err = coroutine.resume(co)
			if not ok then print(err) end
		else
			state = "DONE"
		end
	end, ...)
	if state == "RUNNING" then
		state = "YIELDED"
		coroutine.yield()
		state = "DONE" -- not really needed
	end

```

EDIT 2 : I set up a github repo to checkout the whole code if necessary  
[nakama-love2d repository](https://github.com/shioridotdev/nakama-love2d)

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [December 17, 2021, 3:01pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/5 "2021-12-17T15:01:02Z")

</div>

Hello there !

Still in need of some hint.  
Trying to work around it but still same issue.

---

<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:** [January 4, 2022, 5:38pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/6 "2022-01-04T17:38:35Z")

</div>

@shioridotdev I’m a bit lost on where you’re stuck. Would you be able to summarize it again?

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [January 23, 2022, 2:05am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/7 "2022-01-23T02:05:08Z")

</div>

Hello,

Thanks for your answer, I’m sorry for being late in the respond and sorry if my first post was not too clear, I will try to translate better my issue in English, feel free to ask me again if I didn’t write it properly again.

**What I’m trying to do:**  
Setting up a client base on Love2D game engine (LUA language) and make it workable with Nakama Server.

**What is currently working:**  
Client start properly and the log are those next few lines

```auto
init()
authenticate_device() with coroutine
HTTP POST http://127.0.0.1:7350/v2/account/authenticate/device?create=true
DATA {"id":"b417483f-bad6-44e9-c413-04ed336b0dff"}

```

**What is not working:**  
No new user/device are register in the Nakama Server

**How to reproduce it**  
I set up a GIT repository that you can use to see the whole code.  
[nakama-love2d repository](https://github.com/shioridotdev/nakama-love2d)

**Version use**  
Love2d v11.3  
Nakama v3.9.0

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [February 28, 2022, 7:20am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/8 "2022-02-28T07:20:41Z")

</div>

Hello,

I’m coming back on this thread to get some update about my issue that is still  
ongoing.

Currently looking for where it come from.

If anyone got some hint on it I’m listening.

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [February 28, 2022, 1:42pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/9 "2022-02-28T13:42:28Z")

</div>

Hi @shioridotdev

do you get any errors in the server when trying to authenticate?

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [March 1, 2022, 8:25am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/10 "2022-03-01T08:25:31Z")

</div>

Hello @ftkg

The only last docker log I have is the startup message:

```auto
{"level":"info","ts":"2022-02-28T08:04:08.298Z","caller":"main.go:175","msg":"Startup done"}

```

Thanks for your qucik reply

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [March 1, 2022, 12:20pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/11 "2022-03-01T12:20:52Z")

</div>

@shioridotdev Can you capture the error that comes back from `authenticate_device()` and print it out? You can do that using the `pcall()` function.

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [March 6, 2022, 3:57pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/12 "2022-03-06T15:57:47Z")

</div>

Hello,

Can you guide me for using the pcall function?  
When trying to use it I got this as output:

```auto
false attempt to call a table value

```

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [March 6, 2022, 4:08pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/13 "2022-03-06T16:08:35Z")

</div>

Also on my previous message you got the github page for the project if you got time to look on it.

Thanks

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [March 8, 2022, 2:07pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/14 "2022-03-08T14:07:44Z")

</div>

See some examples here: [nakama-project-template/daily\_rewards.lua at master · heroiclabs/nakama-project-template · GitHub](https://github.com/heroiclabs/nakama-project-template/blob/master/daily_rewards.lua)

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [March 8, 2022, 2:10pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/15 "2022-03-08T14:10:58Z")

</div>

Thanks for the reply, will look on it and get back here for the log.

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [March 15, 2022, 11:37am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/16 "2022-03-15T11:37:39Z")

</div>

Hello,

Just a fallback on the current issue.  
I can’t seems to found any error output on the nakama log.

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [April 7, 2022, 1:05am UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/17 "2022-04-07T01:05:03Z")

</div>

Hello,

Sorry to push again this post but I still don’t found any solution to my issue.

Thanks a lot for your time

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [April 7, 2022, 2:37pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/18 "2022-04-07T14:37:02Z")

</div>

Can you post your new code with the `pcall()` function?

---

<div class="post-metadata">

**Author:** ![shioridotdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/shioridotdev/32/965_2.png) [@shioridotdev](https://forum.heroiclabs.com/u/shioridotdev)\
**Post date:** [August 28, 2022, 3:36pm UTC](https://forum.heroiclabs.com/t/love2d-with-nakama/2163/19 "2022-08-28T15:36:52Z")

</div>

Sorry I got issue and couldn’t continue to look up it.

I got the following error while doing an http request :

```auto
authenticate_email() with coroutine
HTTP POST http://localhost:7350/v2/account/authenticate/email?username=britzl&create=true
DATA {"email":"bjorn@defold.se","password":"foobar123"}
{"code":3, "message":"invalid character 'P' looking for beginning of value"} 400 table: 0x010de8ac28 HTTP/1.1 400 Bad Request

```
