Just dipped my toes into the world of Meteor and managed to create a simple turn-based multiplayer game.
When player 2 joins the game, I update the Game collection using a Meteor.method
. However, when I try to retrieve that update in another Meteor.method
, I have to use Games.find()
again to access the updated value.
Is there a way for me to store the current Game instance so that all my Meteor.methods
can access it?
If this were on the client-side, I would typically use reactive-vars
, but that doesn't seem to be an option here.
Edit:
Meteor.methods({
startGame: function() {
return Games.insert({
players: [{
_id: Meteor.userId()
}]
});
},
joinGame: function(game) {
return Games.update({
_id: game._id
}, {
$set: {
endsAt: new Date().getTime() + 10000
},
$push: {
players: Meteor.userId()
}
});
},
getDataFromGame: function() {
// Struggling to find a way to access data from the game inside other methods
// without having to use Games.find
// Any suggestions?
}
});
I attempted to save the current game within the methods object, but it didn't reactively update. Not sure what steps to take next.