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.
# 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 😉
Is there a way to assign the obtained average to a variable and display it (like with "\v[x]" in a text box)?
# 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 🙂
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.
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.
lol live and learn ^_^
I could accept partial responsibility for not initially stating where to pop it 😀
Sits waiting for Shaz to close another thread I have solved before her Mwahaha...
Detective Dek - on the case...