How to capture Peak energyAverage value

Hello:

I would like to use the showNumber() to show the peak (highest) energyAverage value. How can I do this?

Thanks,

Here’s one way to do it:

// set up a variable to track the max energy average
var maxEV = -9999; // any very low value will do

// set up  your display function to show the current maximum
function showNumberMaxEnergyAverage() {
   return maxEV;
}

// then, in beforeRender, check to see if the energyAverage is higher than
// our saved max.  If so, save the new value.  
function beforeRender(delta) {
  if (energyAverage > maxEV) maxEV = energyAverage;

....  (other beforeRender() code) ...
}
2 Likes

Thanks. I’ll give this a try.

Thanks @ zranger1. The code works great and with your explanation I understand how to apply the same strategy in similar situations. Cheers.

1 Like