1

So currently I am making a system for a game that works something like this.

You have Value A/Turquoise, which is 1

You have Value B/Orange, which is 0.5

I first move Value A decimal point 2 times to the left, making Value A 100, I then divide value A by 1.25, and then move the decimal point right 2 times, making the final value 0.8

I then do the same thing for Value B, I move the decimal point to make it 50, divide by 2.5, then move the decimal point back to where it becomes 0.2

We now have Value C/Red, which is the sum of the calculated values of A and B, which should be 1. Value A affects Value C by 80%, while Value B affects Value C by 20%. I think it's working as intended.

$$\color{red}{0.8}\\ \color{orange}{0.2}\\ \color{green}{1.0}$$

If I change the value of Value B to 0.3 instead of 0.5, we get this.

$$\color{red}{0.80}\\ \color{orange}{0.12}\\ \color{green}{0.92}$$

So the calculation is working as intended (I'm pretty sure), but the problem is, if I go higher than 0.5 the value keeps going up, I don't want it like that. If the real float of Value B is 0.7, I want the calculated value to be 0.12, as if it the real float of Value B is 0.3. Now with the way programming works, I can say if the float of Value B is greater than 0.5 then we will use the new calculation. The problem is I don't know how to do that, what would I need to do to make that work.

Now I get a solid C in High School math classes, so I'm certainly not the brightest (and didn't really pay attention) so I have absolutely no clue what to do or what to even look up because I don't know the names or terms or concepts that would be associated with the problem I am in right now.

What is the solution here? Thanks in advance for the help! If you need more clarification on what exactly I need don't be afraid to ask!

Théophile
  • 24,627
Xasthur
  • 11
  • 1
    Algebra will serve you well here. For example: "I first move Value A decimal point $2$ times to the left, making Value A $100$, I then divide value A by $1.25$, and then move the decimal point right $2$ times." This is the same as $$(((a \times 100) \div 1.25) \div 100).$$ The factors of $100$ cancel out (do you need to shift the decimal place over only to shift it right back?), and so this simplifies to $a/1.25$, or, equivalently, $\frac45 a$. This takes care of an entire paragraph, and is much easier to work with. – Théophile Feb 16 '23 at 04:32
  • Well like I said, I'm bad at math, so I really wasn't aware that was the way to write it. I only shifted the decimal place because I was smashing my keyboard (hyperbole) trying to figure out the math for decimal points, so I just made it into a whole number to make my life easier. Value C needs to be summed up as 1.0 because that's the thing I will program this to will not let me input anything higher than 1.0 – Xasthur Feb 16 '23 at 04:43
  • It is really unclear what you want. From your description it seems you are calculating $C$ to be $C=A/1.25+B/2.5 = (4A+2B)/5$. Are $A$ and $B$ always between $0$ and $1$? You say you want $C$ to be $1$, but do you actually mean that? You seems to allow $C=0.92$, so did you intend to say that $C$ needs to be between $0$ and $1$? Your confusing description of a behaviour change when $B>0.5$ makes me think you actually want to use $\min(B,1-B)$ in the calculation instead of $B$, which will limit the range of $C$ to $[0,1]$ if $A$ and $B$ are in that range. – Jaap Scherphuis Feb 16 '23 at 10:12
  • Yeah sorry, when I said I need Value C to be summed up as 1.0 I meant like that's the highest it will ever go. min(B,1−B) This worked! Thanks a whole lot man! – Xasthur Feb 16 '23 at 15:25

0 Answers0