# Change a value in connection with another value help

1. What do you want to achieve? Title explanation :

Let’s take two groups of numbers:

The first one is between 1 and 60 and is composed of all the numbers between these two numbers. In this group, there is a value that we will call “A-value” that moves every second between 1 and 60.

The second is between 2000 and 15 000 and is composed of all the numbers between these two numbers. In this group, there is also a value that we will call “B-value” that waits to move between 2000 and 15 000.

To move, the B-value needs to be linked to the A-value but at its scale. So if the A-value is 1 then the B-value would be 15 000, and as the A-value goes up, the B-value would go down until it reaches 2000 when the A-value reaches 60.

Is it possible to do a mathematical calculation in a loop that would allow to detect the B-value every second in relation to the A-value? I hope you will understand my question (I don’t speak English very well so I used a translator for this message).

The math would look like this:

``````local aMin = 1
local aMax = 60

local bMin = 2000
local bMax = 15000

local function bFromA(a)
local aScale = (a - aMin) / aMax

local bScaleFactor = (bMax - bMin)

-- The `1 - aScale` flips the direction so a increasing becomes b decreasing
local b = bScaleFactor * (1 - aScale) + bMin
end

-- You can do the opposite of the function above to go from a to b
``````
1 Like

Hello thank you it work perfectly

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.