# How to capture Peak energyAverage value

**URL:** <https://forum.electromage.com/t/how-to-capture-peak-energyaverage-value/2266>\
**Category:** Uncategorized\
**Created:** [June 25, 2022, 10:11pm UTC](https://forum.electromage.com/t/how-to-capture-peak-energyaverage-value/2266 "2022-06-25T22:11:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamehana](https://forum.electromage.com/letter_avatar_proxy/v4/letter/k/3be4f8/32.png) [@Kamehana](https://forum.electromage.com/u/Kamehana)\
**Post date:** [June 25, 2022, 10:11pm UTC](https://forum.electromage.com/t/how-to-capture-peak-energyaverage-value/2266/1 "2022-06-25T22:11:01Z")

</div>

Hello:

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

Thanks,

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [June 26, 2022, 4:37am UTC](https://forum.electromage.com/t/how-to-capture-peak-energyaverage-value/2266/2 "2022-06-26T04:37:34Z")

</div>

Here’s one way to do it:

```javascript
// 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) ...
}

```

---

<div class="post-metadata">

**Author:** ![Kamehana](https://forum.electromage.com/letter_avatar_proxy/v4/letter/k/3be4f8/32.png) [@Kamehana](https://forum.electromage.com/u/Kamehana)\
**Post date:** [June 26, 2022, 4:41am UTC](https://forum.electromage.com/t/how-to-capture-peak-energyaverage-value/2266/3 "2022-06-26T04:41:20Z")

</div>

Thanks. I’ll give this a try.

---

<div class="post-metadata">

**Author:** ![Kamehana](https://forum.electromage.com/letter_avatar_proxy/v4/letter/k/3be4f8/32.png) [@Kamehana](https://forum.electromage.com/u/Kamehana)\
**Post date:** [June 26, 2022, 7:48pm UTC](https://forum.electromage.com/t/how-to-capture-peak-energyaverage-value/2266/4 "2022-06-26T19:48:38Z")

</div>

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