2016-06-22 6 views
0

を取得します。流星モンゴは私が流星メソッドmoveFishを呼び出してタイマーを持っているサーバー上の流星ゲーム <a href="https://i.stack.imgur.com/xGHHK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xGHHK.jpg" alt="enter image description here"></a></p> <p>を持って、この値

方法は、すべての魚が生きていると彼らは

Meteor.methods({ 
    moveFish: function(id, speed) { 
     Meteor.users.update({ "fish.alive": true }, { $inc: { "fish.positionX": 2 } }) 
    } 
}) 

enter image description here

どのように私はthis.fish.speedを使用して魚を移動しない代わりに、値2

Meteor.users.update({ "fish.alive": true }, { $inc: { "fish.positionX": 2 } }) 

*を移動させる選択

Meteor.startup(() => { 
    Meteor.setInterval(function(){ 
     Meteor.call("moveFish") 
    }, 40); 
}); 

お知らせ帽子です

Meteor.users.update({ "fish.alive": true }, { $inc: { "fish.positionX": "fish.speed" } }) 

Meteor.users.find().map(function(user) { x = user.fish.speed Meteor.users.update(user, {$inc: {"fish.positionX": x} }) }) 

答えて

0

は、残念ながら、ドキュメントが更新操作に自分自身への参照を使用することはできません動作します動作しません。 。だ

Meteor.users.findAll({ "fish.alive": true }).fetch().forEach(function(fish) { 
    fish.positionX += fish.speed; 
    fish.save(); 
}); 
+0

は全く Meteor.users.find()マップ(機能(ユーザー){ のx =ユーザーに動作します:

あなたが最初にそれを見つけて、この場合には、手動ですべての文書を反復処理する必要があります。 fish.speed Meteor.users.update(user、{$ inc:{"fish.positionX":x}}) }); – Alexander

+0

はい、ドキュメント自体は "更新"機能よりもはるかに簡単です。 –

+0

あなたはそうです。しかし、私は良いパフォーマンスに自信がありません。だから私は望んでいる – Alexander

関連する問題

 関連する問題