Match_kick not doing anything

I’m trying to implement a timeout function that kicks inactive players if they haven’t submitted a certain action in a certain amount of time. After correctly registering presences in the match state, using the function match_kick(presence) in said presences doesn’t do anything, as shown in the following screenshot:

The code that kicks the players is:

-- M.match_check_timeout(dispatcher,state)
-- ...
for _, id in ipairs(state.players) do
  if state.formation[id] == nil then
    dispatcher.match_kick(state.presences[id])
    print("kicked player "..state.presences[id].username)
  end
end
-- ...

And the code that tracks the presences before and after the kick:

-- match_loop
print("presences before timeout: ")
for k,v in pairs(state.presences) do
    print(state.presences[k].username)
end
M.match_check_timeout(dispatcher,state)
print("presences after timeout: ")
for k,v in pairs(state.presences) do
    print(state.presences[k].username)
end

Am I doing something wrong? Is that the correct usage of match_kick?
Please help! Thanks in advance!

As the docs show, dispatcher.match_kick takes a table (Lua’s list-like structure) of presences to kick. You’re giving it a single presence.

Try dispatcher.match_kick({state.presences[id]}) instead.

Side note - the before/after timeout check won’t show any difference if you don’t update the state’s list of presences when you kick a presence. That list is maintained by your code, in your match state, and is not automatically updated by dispatcher functions.

1 Like

Sorry for the thread necromancy, but something is not clear to me. We’re supposed to send a table to the dispatcher.match_kick() but since LUA does not have Array structures but only dictionaries, should the ID of the user to kick be in table keys or in the table values?

@db0 You pass in what we call a Lua table array. This is a Lua table which is numerically indexed. A Lua table array looks like:

local arr = { "one", "two", "three" }

Whereas a Lua table would look like:

local tbl = { "key" = "one", "key2" = "two", "key3" = "three" }

In the case of the dispatcher match_kick function in Nakama’s server framework your code should look like:

-- presence1 is the field given when the user joins the match in match_join
local kicklist = { presence1, presence2 }
dispatcher.match_kick(kicklist)

Hope that helps.

1 Like

Yes perfect! The table array is effectively a table with numerical indexes, righ? So local arr = { "one", "two", "three" } is the same as local arr = { 0 = "one", 1 = "two", 2 = "three" }, right?

1 Like

@db0 Yes absolutely. Tables in Lua are really always map types just they use integer key names when we refer to them as table “arrays”. Your code is perfectly equivalent as far as Lua interprets it. :+1:

1 Like

@db0 FYI
Lua “array” starts at 1 not zero

2 Likes