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:
-- 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!
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.
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?
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?
@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.