Posts ID:156472 Favorites Creations Medals
 ID:156472   Sep 30 2010, 1:03 am Is it possible to make a variable thats value is affected by another variable? For example, I have 47 in a speed skill and 60 stamina. the 60 of stamina will give all my chosen variables a 10% benefit. So with 0 stamina I have 47 speed skill. With 60 stamina I add 10% which is 6 so my speed ends up at 53. I want this variable to be affected without having to do it manually every time Its shown or used.
 #1 Sep 30 2010, 7:05 am Slic3y wrote: I want this variable to be affected without having to do it manually every time Its shown or used. Then use a proc (or perhaps a #define macro) to do so. It's also possible to keep track of the base value of the stat, then change the actual stat (what's used)'s value according to the base one whenever stamina changes (which should be done through a central proc, of course).
Instead of changing the player's stamina by just adding or subtracting from it like this:
 ```stamina += 10//orstamina -= 10 ```

You can make a proc that you use instead that can take all the other variables into account when you change stamina
 ```adjustStamina(10)//oradjustStamina(-10)mob/proc/adjustStamina(value) stamina += value //Calculations for the other values goes here ```

As long as you always call that proc whenever there is a change in the player's stamina, then the other stats will be adjusted too.
In response to Gunbuddy13 (#2)
You can also use procs in this fashion to manage or ensure that the stats do not go over or under any numbers you would think to be 'illegal' in your game.

 ```mob var/my_var = 5 proc/Change_MyVar(N=0 as num) N = round(N) // Floor N -- integers only! if (N < 0) N = 0 else if (N > 999) N = 999 my_var = N ```
In response to Makeii (#3)
Makeii wrote:
You can also use procs in this fashion to manage or ensure that the stats do not go over or under any numbers you would think to be 'illegal' in your game.

 ```> mob> var/my_var = 5> > proc/Change_MyVar(N=0 as num)> N = round(N) // Floor N -- integers only!> if (N < 0)> N = 0> else if (N > 999)> N = 999> > my_var = N> ```

max() and min() work just as easily. =P
 #5 Sep 30 2010, 1:39 pm In response to Teh Governator (#4) Ah, awesome! Thanks guys.
In response to Teh Governator (#4)
Teh Governator wrote:
Makeii wrote:
You can also use procs in this fashion to manage or ensure that the stats do not go over or under any numbers you would think to be 'illegal' in your game.

 ```> > mob> > var/my_var = 5> > > > proc/Change_MyVar(N=0 as num)> > N = round(N) // Floor N -- integers only!> > if (N < 0)> > N = 0> > else if (N > 999)> > N = 999> > > > my_var = N> > ```

max() and min() work just as easily. =P

 ```N=max(0,min(999,round(N))) ```