Currently, I have both the game ID and player ID stored in session variables.
Games.insert({
board : hex_board(7),
players : [{id: 0, hexIds: []}, {id: 1, hexIds: []}],
});
At this point, I am facing a challenge:
Games.update(Session.get("game"), {$addToSet: {players: ""}});
I'm unsure how to specify which element in the players list to target, but the condition is based on Session.get("activePlayer")
.
I almost have it working by hardcoding the key as 0 or 1; I just need to make it dynamic based on the activePlayer variable
Games.update(Session.get("game"), {
$addToSet: {
"players." + Session.get("activePlayer") + ".hexIds": Session.get("selected_hex")
}
});
Solution implemented as a method
Meteor.methods({
addHexIds: function(hexIds, player, game) {
Games.update({_id: game, "players.id": player}, {
$addToSet: {
"players.$.hexIds": hexIds
}
});
}
});