I got stuck again with my code. Im coding web based game and I'd like to share variables within every view.
Every user has created his own race. and every race has lot of stuff inside. ie - commodities{money, energy,...} planets{owned, built,...}
as in every strategy, I want to show those values on every page after user logs in. Theese values are going to be changed everytime user performs some action.
for no I'm using helper module`
dbValues.commodities = function(userId, callback){
Race.findOne({"owner.id" : userId}, function(err, race){
if(err){
console.log(err)
} else {
var money = race.commodities.money;
var energy = race.commodities.energy;
var metals = race.commodities.metals;
var techs = race.commodities.techs;
var soldiers = race.commodities.soldiers;
callback(money, energy, metals, techs, soldiers);
}
});
}`
Id like to avoid using calling this function on every route, as theese are only values for commodities.
Can you give me some advice how to do that?
I want to use it in partial what will be same on every page after login.. Is there a way how to just place it for partial? for other pages I want to show them specialy I can call this function in router
Thank you
via SLUNlCKO
No comments:
Post a Comment