why is this adding values instead of multiplying?

    public float GetFishPerSec()
    {
        float tick2 = 0;
        float tick1 = 0;
        float tick = 0;
        foreach(float item in tickValue)
        {
            tick += idleCount[0] * tickValue[0];
            tick1 += idleCount[1] * tickValue[1];
            tick2 += idleCount[2] * tickValue[2];
        }
        return tick + tick1 + tick2;   
    }

been trying to work this out for the last couple hours, and i am not understanding why this is taking the idlecount value and the tickvalue and adding them together instead of mulitplying it.

        tickValue [0] = 0.2f;
        tickValue [1] = 0.7f;
        tickValue [2] = 1.5f;
        tickValue [3] = 3;
        tickValue [4] = 5.5f;
        tickValue [5] = 7;
   
        idleCost [0] = 500;
        idleCost [1] = 1200;
        idleCost [2] = 5000;
        idleCost [3] = 150000;
        idleCost [4] = 500000;
        idleCost [5] = 1000000;
   
        idleCount [0] = 0;
        idleCount [1] = 0;
        idleCount [2] = 0;
        idleCount [3] = 0;
        idleCount [4] = 0;
        idleCount [5] = 0;

as an example when i get 1 count of the [0] part of the array it goes 1 + 0.2 instead of 1 times 0.2, can anyone tell me why this is not multiplying? Thank you.

Firstly your all idleCount array is 0, so it is always multiplying by 0. Secondly when doing foreach you need to use item instead of tickValue. But in general I don’t really understand what are you trying to achieve here. :slight_smile:

the 0s are all there as the starting point for each one. as soon as you purchase something it ups to 1 at the min, and then does the math. thanks the item instead of tickvalue is probably the issue. Thank you! thought you used the array name there

So it should be float item in item for my foreach?

the results I am getting currently is its adding the 1 count to the 0.2 tick value to get 1.2 instead of multiplying it to get 0.2 then 0.4 with a 2nd count and so on

LoL how about u tell us what do you want to achieve ? We cant help you if we dont understand what do you want. Like using your GPS, u need to know your destination coordinate, keep driving without a direction wont help.

2 Likes