I’m trying to create a simple lobby-like setup, where someone will create a lobby and wait for players to join before starting the game. I’m using Authoritative matches for this.
As a workaround to my previous attempt, I tried to simply add the notification immediately after creating the match. My test notification code is like this
nk.notification_send("76a147a1-68e5-4da1-aeb9-a8a6d0d89107", "New match", nk.match_get(matchid), OpCodes.new_match_notification, nil, false)
for _, match in ipairs(nk.match_list()) do
nk.logger_info(string.format("List all Matches - Match id %s", match.match_id))
Effectively every time a match is created, I want all logged-in users to receive the list of all currently available matches.
I’m running into two issues
- When the
nk.match_list() is run immediately after creating a match, it does not yet “see” the new match and therefore does not return it in its table results. I also found no API to “sleep” for a millisecond or somethign to allow the match creation to finalize.
- I don’t see a way to loop through all currently logged in users, or all users for that matter. Is there such a method?
The discussion on your previous thread is still ongoing, but I’ll answer your questions here briefly:
There may be a delay in the milliseconds range between creating a match and it appearing in match listings. It’s extremely rare for this to be an issue as you’ll know it exists and its properties - after all you’ve just created it in the same context!
If possible avoid using this pattern. Depending on your use case there’s generally a better pattern or a different approach that would probably do the job better.
You can add your users to a stream as soon as they connect, and list that stream to get a complete view of everyone online.
What are you planning to use this for? There may be an easier way to achieve what you need.
It’s a simple lobby setup for card games (similar to what you can see,say, in jinteki.net). Any player can create a lobby and wait for opponents to join. The lobby should be immediately visible to anyone currently logged in at that point and they can join that lobby where they select their deck before the game starts.
This attempt is how to notify all players using a “push” mechanism rather than relying on my current “pull” implementation (where each players retrieves all active lobbies ever 5 seconds)