I'm doing matchmaking + realtime for my card game and I want to be able to start RT sessions with only one player (to avoid duplicating code and keep my structure linear)
current flow is:
player can start matchmaking either alone or with friends invited earlier, to do this I have a LogEventRequest with"Spark.getConfig().getMatchConfig(data.match).createPendingMatch(data.matchGroup, skill, playerData)", where playerData is curent player + players loaded from Ids passed by client
player(s) receive a MatchFoundMessage and starts an RT session
client code sends moves to server through RT, server relays packets to all clients (including sender) and clients react to player moves when they receive them (including moves sent by themselves)
i'm trying to match fake players with this code in MatchNotFoundMessage (global):
var player = Spark.getPlayer();
var data = Spark.getData();
var playerData = [player];
var matchCfg = Spark.getConfig().getMatchConfig(data.matchShortCode);
var maxp = matchCfg.getMaxPlayers(); // this is 4
var bots = Spark.runtimeCollection("bots").find(); // bots collection contains a list of fake player ids
while (playerData.length < maxp) {
var id = bots.hasNext() ? bots.next().playerId : null;
if (!id) {
// create a fake player and add it to bots collection
// this is temp, I plan to have a pool of users and selecting randomly from that
var rr = new SparkRequests.DeviceAuthenticationRequest();
rr.deviceId = "server-"+ Spark.runtimeCollection("bots").count();
rr.deviceOS = "BOT";
id = rr.Send().userId;
Spark.runtimeCollection("bots").insert({playerId:id});
}
var bot = Spark.loadPlayer(id);
Spark.getLog().debug({bot:bot.getPlayerId(),name:bot.getUserName()});
playerData.push(bot);
}
Spark.getLog().info({before:"pm",players:playerData.length}); // length is 4
var pm = matchCfg.createPendingMatch(data.matchGroup , DataModel.User.Current().Skill, playerData);
Spark.getLog().info({after:"pm",players:pm.getMatchedPlayers().length}); // length is 1
but bots are not added to the pending match. I tried to hardcode the ID of another (real) player but is still not matching
is there a recommended way to force the creation of a match?
Best Answer
C
Customer Support
said
over 5 years ago
Hi Shah,
You can do it now. Set the minPlayer value in your match to 1 and send a MatchMakingRequest as a player and they will be in the match by themselves.
It's probably not a great idea to create a new bot each time you are doing this. You are just going to end up creating a new player each time a match is created which isn't Ideal. You should instead just create a minimal amount of bot accounts for this use and then when creating a pending match as a player include the bot account playerId so you can create it.
Are you getting a specific error when trying to attempt this with your custom code above ?
Thanks,
Liam
M
Mauro Ronchi
said
over 6 years ago
Hi Liam,
I am not creating a new user each time. the code above first looks for an available id in the "bots" runtimeCollection and creates a new player only if there are none (i.e. the first time it executed - I am still in the preview environment, I plan to put that in the "Game Published" system cloud code before I go live)
the code I run is exactly as you posted:
var matchCfg = Spark.getConfig().getMatchConfig(data.matchShortCode);
// ... fill playerData with [player, bot1, bot2, bot3]
var pendingMatch = matchCfg.createPendingMatch(data.matchGroup , skill, playerData);
I don't get any error, but if I print pendingMatch.getMatchedPlayers().length it returns 1 - i.e. only myself. then I get another MatchNotFoundMessage after it expires (and it looped until I commented out the code)
M
Mauro Ronchi
said
over 6 years ago
(ps. everytime I post anything I land on an error page with a "We're sorry, but something went wrong." message and I have to go back to the index)
J
James Ford
said
over 6 years ago
I'm not sure why the mechanics to create an RTSession and/or join/leave one are so opaque and only accessible within the context of matchmaking. I vote for exposing a much more straightforward api... like RequestCreateRTSession, RequestJoinRTSession, RequestLeaveRTSession.
1 person likes this
S
Simin Liu
said
almost 6 years ago
How do I request to leave the current RTSession(not by disconnect the interenet but by say click a button), currently I tried to use EndSessionRequest, but doesn't seem to work.
Starting a match with a single player is still in the backlog. I'll update you when the work has started.
Sean
S
Shah Abdullah
said
over 5 years ago
Hey Sean,
Please update me about single player match starting and other player can join same session. At the moment I am creating RPG game and for that I cannot make sure to get all players online on same time but we need to spawn as player joins room.
Will be waiting for your prompt reply.
Customer Support
said
over 5 years ago
Answer
Hi Shah,
You can do it now. Set the minPlayer value in your match to 1 and send a MatchMakingRequest as a player and they will be in the match by themselves.
Regards,
Liam
S
Shah Abdullah
said
over 5 years ago
Yes Liam, but when other player joins the match from other client it creates seperate RT session and have no info about first player and for checking I printed participants in current RT session it returns 1 only.
F
Fimiam Gamedev
said
over 5 years ago
Shah, I think you just need to turn on "drop-in/drop-out" toogle in your match settings.
S
Shah Abdullah
said
over 5 years ago
My scenario is when player A joins the room(GSMatch) which is having limit of 10 player, he can explore and move around the map by creating RT session. Other players joining same match should spawn in same environment and at joining should return callback matchupdated. Is it possible to start real time session for one player and after that other players can join that same RT session depending on GS Match in my case it is WorldCluster.
Mauro Ronchi
hi,
I'm doing matchmaking + realtime for my card game and I want to be able to start RT sessions with only one player (to avoid duplicating code and keep my structure linear)
current flow is:
but bots are not added to the pending match. I tried to hardcode the ID of another (real) player but is still not matching
is there a recommended way to force the creation of a match?
Hi Shah,
You can do it now. Set the minPlayer value in your match to 1 and send a MatchMakingRequest as a player and they will be in the match by themselves.
Regards,
Liam
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Mauro,
It's probably not a great idea to create a new bot each time you are doing this. You are just going to end up creating a new player each time a match is created which isn't Ideal. You should instead just create a minimal amount of bot accounts for this use and then when creating a pending match as a player include the bot account playerId so you can create it.
Are you getting a specific error when trying to attempt this with your custom code above ?
Thanks,
Liam
Mauro Ronchi
Hi Liam,
I am not creating a new user each time. the code above first looks for an available id in the "bots" runtimeCollection and creates a new player only if there are none (i.e. the first time it executed - I am still in the preview environment, I plan to put that in the "Game Published" system cloud code before I go live)
the code I run is exactly as you posted:
I don't get any error, but if I print pendingMatch.getMatchedPlayers().length it returns 1 - i.e. only myself. then I get another MatchNotFoundMessage after it expires (and it looped until I commented out the code)
Mauro Ronchi
(ps. everytime I post anything I land on an error page with a "We're sorry, but something went wrong." message and I have to go back to the index)
James Ford
I'm not sure why the mechanics to create an RTSession and/or join/leave one are so opaque and only accessible within the context of matchmaking. I vote for exposing a much more straightforward api... like RequestCreateRTSession, RequestJoinRTSession, RequestLeaveRTSession.
1 person likes this
Simin Liu
How do I request to leave the current RTSession(not by disconnect the interenet but by say click a button), currently I tried to use EndSessionRequest, but doesn't seem to work.
Christopher Bonnell
SparkMatch.removePlayers()
1 person likes this
Customer Support
Starting a match with a single player is still in the backlog.
I'll update you when the work has started.
Sean
Shah Abdullah
Hey Sean,
Please update me about single player match starting and other player can join same session. At the moment I am creating RPG game and for that I cannot make sure to get all players online on same time but we need to spawn as player joins room.
Will be waiting for your prompt reply.
Customer Support
Hi Shah,
You can do it now. Set the minPlayer value in your match to 1 and send a MatchMakingRequest as a player and they will be in the match by themselves.
Regards,
Liam
Shah Abdullah
Yes Liam, but when other player joins the match from other client it creates seperate RT session and have no info about first player and for checking I printed participants in current RT session it returns 1 only.
Fimiam Gamedev
Shah, I think you just need to turn on "drop-in/drop-out" toogle in your match settings.
Shah Abdullah
My scenario is when player A joins the room(GSMatch) which is having limit of 10 player, he can explore and move around the map by creating RT session. Other players joining same match should spawn in same environment and at joining should return callback matchupdated. Is it possible to start real time session for one player and after that other players can join that same RT session depending on GS Match in my case it is WorldCluster.
1 person likes this
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics