Hi, I'm working on a game which involves a "budget" which has a bunch of variables on it which you can increase or decrease, the problem I noticed is that when I raise or lower one of the variables, it doesn't change the overall balance. It still displays the original budget balance, as opposed to the new one when I've modified sections of the budget. I created a function which re-declares the budget balance variable whenever you modify a section of the budget, and now it updates normally. While this is fine and dandy, there are a bunch of variables in my game which are just a combination of other variables added up and such, so the function gets bigger and bigger as I make more progress on the game. I assume there must be a less cpu intensive way (Not that it lags, but its always good to be efficient with your code) than recalculating a bunch of variables anytime you change one value.
My question is: Does anyone know of a better way to refresh variables like I've done with this function? To clarify, the script works and everything, I just want to know if there is a more efficient way of doing what I want. The function I use to refresh the variables gets bigger whenever I add a new variable combination (a variable which is just a bunch of other variables added up). I was thinking of using an onClipEvent(EnterFrame) handler when declaring them so that the variable is just constantly declaring itself, but that might be even more cpu intensive than just redeclaring it anytime you modify the budget (which is really the only time it needs to be declared/refreshed).
Example of what I mean:
(In one as file)
var budg_agriculture:Number = -450;
var budg_manufacturing:Number = -250;
var budg_balance:Number = _root.budg_agriculture + _root.budg_manufacturing;
If someone changes the budg_agriculture value, the budg_balance doesnt update, so i've created:
(In another file)
function VarRefresh(){
_root.budg_balance = _root.budg_agriculture + _root.budg_manufacturing;
}
And I just call VarRefresh(); everytime a variable is modified. It works, but again, it seems inefficient and I need to add new variables to the "VarRefresh" function anytime I add one, to make sure it updates properly.