|
KurtDH Beginner
Joined: 14 Sep 2004 Posts: 17
|
Posted: Tue Nov 02, 2004 11:41 pm
Math question |
I'm retrieving the results of a roll, adding up all the stats, and sending that number to the @primarystats variable.
I'm rolling thousands of times. Each time, the @primarystats variable is replaced with the new number.
What I'd like to do is send the results of @primarystats somewhere, so I can build a trigger that will formulate the average.
So for example, the first roll stats total equals 400. The second roll stats total equals 300. The third roll stats total equals 200. If these were my only three rolls, I'd want a trigger that adds 400, 300, and 200, then divides by 3, in order to get the average. If I had rolled 5,000 times, I'd want a trigger that adds up all 5,000 numbers, then divides by 5,000. Is there any easy way to do this? Will zMUD eventually get bogged down if too many numbers are added to this "pool"? |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Wed Nov 03, 2004 7:42 am |
Use a list variable. add up all the stats, then send that number to the PrimaryStats variable via:
#var PrimaryStats %additem(##,@PrimaryStats)
Then to calculate the average:
#var AverageTotal 0
#forall @PrimaryStats {#add AverageTotal %i}
#SAY Average total is %eval(%float(@Averagetotal)/%numitems(@PrimaryStats)) |
|
|
|
KurtDH Beginner
Joined: 14 Sep 2004 Posts: 17
|
Posted: Wed Nov 03, 2004 3:09 pm |
I guess this leads me to ask - how do I use a list variable - and how do I add up all the stats in the list variable?
|
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Wed Nov 03, 2004 4:03 pm |
#ADDITEM read that and the related helpfiles to get you started
|
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Thu Nov 04, 2004 8:38 am |
If you didn't notice, I included in my original post an example script to add up all the values in the list variable:
Quote: |
#var AverageTotal 0
#forall @PrimaryStats {#add AverageTotal %i}
#SAY Average total is %eval(%float(@Averagetotal)/%numitems(@PrimaryStats))
|
The line colored blue is the line that adds up all the values in the list variable. |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Thu Nov 04, 2004 12:40 pm |
And a much quicker way to do it without the need for a var or Forall
#say Average Total %eval(%expandlist(@primaryStats,+)/%float(%numitems(@primaryStats))) |
|
|
|
|
|