2017-08-31 51 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

我的天啊我從未想到的是,覆蓋它!感謝您的支持。我現在換掉它們。 –