# How can I make a bar that shows the distance between one variable and another

**URL:** <https://forums.moddingtree.com/t/how-can-i-make-a-bar-that-shows-the-distance-between-one-variable-and-another/433>\
**Category:** Modding Developers\
**Created:** [February 8, 2022, 1:59am UTC](https://forums.moddingtree.com/t/how-can-i-make-a-bar-that-shows-the-distance-between-one-variable-and-another/433 "2022-02-08T01:59:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alezman](https://forums.moddingtree.com/user_avatar/forums.moddingtree.com/alezman/32/96_2.png) [@alezman](https://forums.moddingtree.com/u/alezman)\
**Post date:** [February 8, 2022, 1:59am UTC](https://forums.moddingtree.com/t/how-can-i-make-a-bar-that-shows-the-distance-between-one-variable-and-another/433/1 "2022-02-08T01:59:49Z")

</div>

be it in progress or be it in percentage im fine with either (or both)

---

<div class="post-metadata">

**Author:** ![thepaperpilot](https://forums.moddingtree.com/user_avatar/forums.moddingtree.com/thepaperpilot/32/74_2.png) [@thepaperpilot](https://forums.moddingtree.com/u/thepaperpilot)\
**Post date:** [February 8, 2022, 2:03am UTC](https://forums.moddingtree.com/t/how-can-i-make-a-bar-that-shows-the-distance-between-one-variable-and-another/433/2 "2022-02-08T02:03:08Z")

</div>

Assuming you’ve already [created the bar](https://github.com/Acamaeda/The-Modding-Tree/blob/master/docs/bars.md), all you have to do is change what the progress function returns.

For example, say you’re trying to see how close your amount of points is to your amount of prestige points. You could do this:

```javascript
{
    ...,
    progress() {
        return player.points.div(player.p.points).clamp(0, 1);
    }
}

```

---

<div class="post-metadata">

**Author:** ![alezman](https://forums.moddingtree.com/user_avatar/forums.moddingtree.com/alezman/32/96_2.png) [@alezman](https://forums.moddingtree.com/u/alezman)\
**Post date:** [February 8, 2022, 2:06am UTC](https://forums.moddingtree.com/t/how-can-i-make-a-bar-that-shows-the-distance-between-one-variable-and-another/433/3 "2022-02-08T02:06:46Z")

</div>

thanks

also wow you respond here faster in the forums instead of discord

---

<div class="post-metadata">

**Author:** ![thepaperpilot](https://forums.moddingtree.com/user_avatar/forums.moddingtree.com/thepaperpilot/32/74_2.png) [@thepaperpilot](https://forums.moddingtree.com/u/thepaperpilot)\
**Post date:** [February 8, 2022, 2:11am UTC](https://forums.moddingtree.com/t/how-can-i-make-a-bar-that-shows-the-distance-between-one-variable-and-another/433/4 "2022-02-08T02:11:48Z")

</div>

I saw you post these example inputs/outputs in discord:

```auto
2 - 4
50%
4 - 4
100%
6 - 4
50%

```

This is a bit more complicated. I think you made a mistake here - the last one should be 66%. I can’t think of a formula that would return 50% in that case but also get smaller as the first number got larger. Assuming I understand the formula you were trying to demonstrate, the function would look like this, where “a” is the first number and “b” is the second (and the base):

```javascript
return a.sub(b).abs().div(a.max(b))

```

---

<div class="post-metadata">

**Author:** ![alezman](https://forums.moddingtree.com/user_avatar/forums.moddingtree.com/alezman/32/96_2.png) [@alezman](https://forums.moddingtree.com/u/alezman)\
**Post date:** [February 8, 2022, 2:29am UTC](https://forums.moddingtree.com/t/how-can-i-make-a-bar-that-shows-the-distance-between-one-variable-and-another/433/5 "2022-02-08T02:29:27Z")

</div>

the first one you made is fine, it’s not really accurate so it’s okay
