Mass average calculation

● ARCHIVED · READ-ONLY
Started by SoulCatapult 12 posts View original ↗
  1. I need to calculate the average of 190 variables. Is there any way to do this efficiently with a script call? Unfortunately, they're not all in a row, if that makes a difference.

    As a test, I tried assigning a range to a variable, but I got the error "Array can't be coerced into Fixnum," so... I came here for help.
  2. # Script Call :# Solo_Variable.get_avg# module Solo_Variable # Array of variable ID's Vars = [1,2,3,4,5,6,7,8,9] # Method. Do not change. def self.get_avg Vars.compact.inject(1) {|r,i| r += ($game_variables.to_i rescue 0) } / Vars.compact.size endend ;)
  3. Is there a way to assign the obtained average to a variable and display it (like with "\v[x]" in a text box)?
  4. # Script Calls :# Solo_Variable.get_avg << returns the value of the variable average.# # Solo_Variable.set_avg << Sets average value into variable Text Var ID# module Solo_Variable # Array of variable ID's Vars = [1,2,3,4,5,6,7,8,9] Text_Var_ID = 10 # # Methods. Do not change. def self.get_avg Vars.compact.inject(1) {|r,i| r += ($game_variables.to_i rescue 0) } / Vars.compact.size end def self.set_avg $game_variables[Text_Var_ID] = get_avg endendThen use \v[number] in text box :)
  5. I can't get it to work... ;_; It just displays either 0 or 1 in the text box.


    I can change "Vars = [x]" to a range, right? Like "[21..39]"?
  6. No, you have to manually insert each variable id. Cause you said they werent all in a row i wrote it that way. Unfortunately, it means you have to type out 190 variable id numbers, but it will work :D

    just pop a comma in between each variable ID number. You can go to a new line as well providing the last character on the previous line was a comma.. like this...

    Code:
    Vars = [1,2,3,4,5,6,7,8,9,10,            11,12,13,14,15,16,17,18,19,20]
  7. I appreciate all your help, but I still must not be doing something right...


    Prior to the script call, I set variables 21-28 to 250, and 29-39 to 500. I manually enter variables 21-39 into the "Var" array in your script. I have "Text_Var_ID" set to 60. I put "\v[60]" in a message box, and it comes out 0 for some reason. :(


    I'm sorry to hassle you like this. Also, I might be willing to restructure my variables if a method for a range (possibly several ranges separated by commas, e.g. "21..39, 54..62" etc.) could easily be created. I'm not sure all 190 variables would fit in the script box anyway... even though the update made the box a lot bigger, it still seems to have a height/line limit that's about half of the visible area.
  8. Script box??

    The only thing in the script box should be the one line script call...

    Solo_Variable.set_avg

    The rest of it is code to be inserted somewhere in your script editor below materials and above main. Actually, as long as its before main...

    Then you use the script call and display the variable text as normal.
  9. Dekita said:
    Script box??

    The only thing in the script box should be the one line script call...

    Solo_Variable.set_avg

    The rest of it is code to be inserted somewhere in your script editor below materials and above main. Actually, as long as its before main...

    Then you use the script call and display the variable text as normal.
    ...

    I am a funny person...

    So, so funny...

    ...Thanks. :blush:
  10. Solo said:
    ...

    I am a funny person...

    So, so funny...

    ...Thanks. :blush:
    lol so did you get it working ok now? thats the main thing really. :D
  11. Dekita said:
    lol so did you get it working ok now? thats the main thing really.
    Yes... yes I did. Thank you so much. :D

    I was putting something in the script box that belonged in the script editor... that is so delightfully amusing.
  12. lol live and learn ^_^

    I could accept partial responsibility for not initially stating where to pop it :D

    Sits waiting for Shaz to close another thread I have solved before her Mwahaha...

    Detective Dek - on the case...