2017-08-31 49 views
0

我正在CLR中编写一个RPG角色构建器,并且在一个事件中,您可以在构建点总数的指导方针中设置角色状态。从总数中扣除旧数据以保持正确的总数

但是,注意到一个简单的问题。如果你点击提交统计按钮,它会不断添加他们的统计数据,使得所使用的构建点的总数越来越高,直到你必须关闭应用并重新启动。

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"); 
      } 

每当消息框出现时,它总是说它使用了0个建立点。 当我注释掉所有Old_Stat_total的东西时,它的行为应该像它应该的那样,但是复合添加使得项目有点笨重。我只是想知道我是否错过了什么,或者我没有正确地做某件事。

回答

0

从代码:

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

Stat_total = Old_Stat_total; 

,你可以看到,你计算Stat_totalOld_Stat_total

+0

我的天啊我从未想到的是,覆盖它!感谢您的支持。我现在换掉它们。 –