Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
KurtDH
Beginner


Joined: 14 Sep 2004
Posts: 17

PostPosted: 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"?
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: 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))
Reply with quote
KurtDH
Beginner


Joined: 14 Sep 2004
Posts: 17

PostPosted: 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?
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Wed Nov 03, 2004 4:03 pm   
 
#ADDITEM read that and the related helpfiles to get you started
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: 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.
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: 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)))
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net