Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Better way to initialize a field in a .. (object?)

1445772518

Edited 1445772547
WurmD
KS Backer
How is a proper way to initialize a field in a (struct? object?) ?  Right now I'm doing that below, in bold    totals = _.reduce(findObjs({ pageid: page, type: 'graphic', isdrawing: false, layer: 'objects' }),function(m,o){ m.bar1+=parseFloat(o.get('bar1_value'),10) || 0; m.bar2+=parseFloat(o.get('bar2_value'),10) || 0; m.bar3+=parseFloat(o.get('bar3_value'),10) || 0; if(m.numberOfcities > 0 ){ // Isn't there a better way/place to initialize a variable?       // variable is supposed to be zero or greater than zero, so if greater do nothing }else{      m.numberOfcities = 0; }
found it, you put it at the end totals = _.reduce(findObjs({ pageid: page, type: 'graphic', isdrawing: false, layer: 'objects' }),function(m,o){ return m; },{ bar1: 0, bar2: 0, bar3: 0, numberOfcities: 0});