Authoritative server example code problem (Or Lua noob issue)

Hey,

I’ve been playing around learning Nakama and trying out how the authoritative server works now. I’m trying the example from the documentation as is, but I’m getting this error:

nakama | {“level”:“error”,“ts”:“2020-11-17T09:40:30.517Z”,“caller”:“server/pipeline_matchmaker.go:85”,“msg”:“Error running Matchmaker Matched hook.”,“error”:“Error running runtime Matchmaker Matched hook: /nakama/data/modules/custommatch.lua:23: attempt to index a non-table object(string) with key ‘format’\nstack traceback:\n\t/nakama/data/modules/custommatch.lua:23: in main chunk\n\t[G]: ?”}

This refers to the code from the authoritative server page, this line:

nk.logger_info(("Matched user '%s' named '%s'"):format(presence.user_id, presence.username))

I haven’t used Lua much in the past few years, so maybe it’s just a Lua-noob issue. I found some object dump code, and tried that and the ‘matched_users’ do look correct, it does include users with both user_id:s and usernames.

EDIT: Got it working by changing how format was handled, to this:
nk.logger_info(string.format(“Matched user ‘%s’ named ‘%s’”,presence.user_id, presence.username))

Unsure why this is, but found out this other way of writing format. Maybe some Lua version missmatch?

Thanks!

Niklas

@nixarn Thanks. We’ll update the docs. We no longer allow the object signal format for the string library in the Lua stdlib because it requires global table lookups which can hurt performance.

It’s a small restriction to apply over standard Lua and has great upsides from a performance perspective in the VM implementation. The best part is that you can still make all the function calls you want with the function call form as you’ve found.

i.e. "string.format(m, args...)" rather than "(m):format(args...)".

Got it - thanks!

1 Like