Is there a function that already does this?
I can't seem to find one.
If not, surely it'd be a case of a loop and adding all the values, dividing by the number of items?
Is there a function that already does this?
I can't seem to find one.
If not, surely it'd be a case of a loop and adding all the values, dividing by the number of items?
I don't think there is a function for this, but its just like what you said, add em all in a loop and divide by the number of items.
Averaging what exactly..?
Averaging "items" in an array.
I was thinking he wanted to use inventory items to average something, was confused.
Generally each number in an Array is an item (outside of Simba etc anyway).
I just have an Array of Tokkul Gained per Fight Cave Run, and thought it would be nice to show on average how much is being gained!
You increase the array one index each time you finish the cave?
All you'd have to do is...
SCAR Code:function AverageOutArray(const TheArray: TIntegerArray): Extended;
var
i, l, n: Integer;
begin
l := Length(TheArray);
for i := 0 to l - 1 do
n := n + TheArray[i];
Result := n / l;
end;
Last edited by Train; 02-27-2011 at 02:45 AM.
That's what I was going to put. The maths seems about right, I could be wrong as the numbers are small..Okay, So say i've had these values.
[10,12,16]. That one variable would be 14 after averaging.
Then on the next run I get 12.
How would you get a proper average from that? Cause the averages of 10,12,16 and 12 isn't 13.
Is that how it's done?
I was writing this before you posted that function, it was aimed at KingKong as he said you only need an array
What does Extending a Function do?
edit: Does it allow for decimals?
Extended is decimals.
If you want a solid number, change Extended to Integer and Result := n / l; to Result := Round(n / l);
Nah, it's an Integer array. Can you get extended arrays (or an array compatible with decimals? Curiosity (I don't need it)).
Cheers Train, now my fight cave runner is only a bit away from being released!
I'm super confused. What's with loops and what not? It's just the amount of tokkul divided by the amount of runs..
It's not.
Cause people might start (like I did), with Tokkul in their inventory!
Say they use it for 10 hours, leave it for a day and then leave it for another 10 hours, They will think that they'll be getting twice as much as they are actually getting, and an extra 4 lines of code prevents this!
StartTokkul - EndTokkul == TokkulGained.
![]()
Check if theres tokkul in the inv, then put that number in a var and subtract it from your gained then divide by runs to find avg.
See, this is why I shouldn't be so tired whilst coding.
Now I feel silly
Oh well, it's nice to have the array! :3
I was considering trying a wave counter, and producing a graph of some sort..
1st run = 100 tokkul, wave 2
2nd run = 200 tokkul, wave 4
etc. Does Simba have graph capabilities? If not, can you make straight lines out of bitmaps to draw on the screen?
edit: I think i'll stick with AverageTIA for now, but i'll keep the other average function as learning material!
Last edited by HarryJames; 02-27-2011 at 03:04 AM.
There's no real like.. graph functions, afaik, but it's not that difficult. Plot it and then draw lines from point to point.
You could try working off of this script for your graphing function, it looks challenging though.
http://villavu.com/forum/showthread.php?t=36548
Otherwise, just write a procedure that generates a text file report including the total Tokkul you recieved, the waves you ran, and the Tokkul you recieved from each wave on average. That would be a lot simpler imo.
I have an idea for the graph.
If not I'll put it as an option in the proggy!
It wouldn't be too difficult to get the highest and lowest (rounded to the nearest 100) to help set the scale. Now we have the scales set, and the graph will be of a determined height/width so we can work out how high a value should go!
Then it's just a case of a scatter graph I think.
There are currently 1 users browsing this thread. (0 members and 1 guests)