Search code examples
c++eventssubtraction

Subtracting old data from total to keep a correct total


I'm programming a RPG character builder in CLR and in one event you can set up your characters stats within the guidelines of a buildpoint total.

However, noticed a simple issue. If you hit the submit stats button it keeps adding their stats making the total of used buildpoints higher and higher till you have to close the app and relaunch.

if (Old_Stat_total >0){
Buildpoints_Max -= Old_Stat_total;
}

             Stat_total = Power_value + Speed_value + Range_value + 
             Precision_value + Durability_value + Potential_value;

             Stat_total = Old_Stat_total;
             Buildpoint_total += Stat_total;
             if (Buildpoint_total > Buildpoints_Max){
                 MessageBox::Show("Exceeded buildpoint allotment");
             }
             else{
                 MessageBox::Show("Total used buildpoints from stats: " + Stat_total + "\n");
             }

Whenever the message box comes up it always says it is using up 0 buildpoints. When I comment out all the Old_Stat_total stuff it behaves as it should but the compounding addition makes the project a little clunky. I'm just wondering if I am missing anything or I'm not doing something correctly.


Solution

  • From your code:

    Stat_total = Power_value + Speed_value + Range_value + 
             Precision_value + Durability_value + Potential_value;
    
    Stat_total = Old_Stat_total;
    

    as you can see, you calculate Stat_total and the overwrite it with Old_Stat_total