Hello again! While tracking down a bug in my Lua code, I found some rather strange and unexpected behavior. I have a function that concatenates 3 variables (each containing a one character string) into a single variable, then returns the value of that variable, which should be a 3 character string. (An example return value from this function might be “AR2”.) When the above function is called, the return value is caught/assigned to a new variable (eg, “temp”).
Here’s the strange and unexpected part: when I add in the code:
nk.logger_info( "This Function: Returned value: " … temp )
The script throws an error:
nakama_1 | {“level”:“warn”,“ts”:“2021-12-08T04:03:31.812Z”,“caller”:“server/match_handler.go:292”,“msg”:“Stopping match after error from match_loop execution”,“mid”:“18b36846-792a-496c-a22c-30cd0cc6a129”,“tick”:60,“error”:“data/modules/myMatchStuff.lua:1037: cannot perform concat operation between string and nil\nstack traceback:\n\tdata/modules/myMatchStuff.lua:1037: in function ‘doing_specific_stuff’\n\tdata/modules/myMatchStuff.lua:1151: in function ‘this_function’\n\tdata/modules/myMatchStuff.lua:1377: in function ‘doing_stuff’\n\tdata/modules/myMatchStuff.lua:1784: in function ‘players_update’\n\tdata/modules/myMatchStuffAPI.lua:53: in main chunk\n\t[G]: ?”}
However, immediately before this error in the log is the line
nakama_1 | {“level”:“info”,“ts”:“2021-12-08T04:03:31.811Z”,“caller”:“server/runtime_lua_nakama.go:1782”,“msg”:“This Function: Returned value: AR3”,“mid”:“18b36846-792a-496c-a22c-30cd0cc6a129”,“runtime”:“lua”}
I understand that concat fails (and throws an error) when working with non-strings (like nil); however, the concat clearly succeeded – otherwise, the info log line couldn’t have appeared in the log. Under what circumstances would a concat throw a “nil” error after successful operation?
Thank you very much for whatever assistance you can provide!
- Versions: Nakama {3.9}, {Linux Docker}
- Server Framework Runtime language (If relevant) {Lua}