HarryJames
2011-02-26 21:17:27
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?
KingKong
2011-02-26 21:21:36
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.
Train
2011-02-26 21:21:52
Averaging what exactly..?
KingKong
2011-02-26 21:24:40
The numbers in the array?
Train
2011-02-26 21:25:41
Averaging "items" in an array.
I was thinking he wanted to use inventory items to average something, was confused.
HarryJames
2011-02-26 21:28:12
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!
KingKong
2011-02-26 21:31:06
From: 05hartor
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 don't need an array to do that, you can just use two variables.
Train
2011-02-26 21:32:44
From: 05hartor
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…
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;
HarryJames
2011-02-26 21:33:26
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.
That's what I was going to put. The maths seems about right, I could be wrong as the numbers are small..
Is that how it's done?
Train
2011-02-26 21:35:51
From: 05hartor
That's what I was going to put. The maths seems about right, I could be wrong as the numbers are small..
Is that how it's done?
Excuse me? I do not comprehend (The quote).
HarryJames
2011-02-26 21:37:03
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?
Train
2011-02-26 21:43:06
Extended is decimals.
If you want a solid number, change Extended to Integer and Result := n / l; to Result := Round(n / l);
KingKong
2011-02-26 21:44:27
From: 05hartor
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?
You mean decimals inside the arrays? then no.
HarryJames
2011-02-26 21:46:43
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 luffs yeww
2011-02-26 21:47:28
I'm super confused. What's with loops and what not? It's just the amount of tokkul divided by the amount of runs..
Train
2011-02-26 21:48:29
From: 05hartor
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!
You have an integer array but the result may be an extended.
Say you have 1 and 2, the function would give 1.5. An array of floats would be [var name]: array of Extended; (or TExtendedArray if it exists).
KingKong
2011-02-26 21:49:29
From: i luffs yeww
I'm super confused. What's with loops and what not? It's just the amount of tokkul divided by the amount of runs..
thats what i was trying to say a few posts ago.
HarryJames
2011-02-26 21:53:18
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!
i luffs yeww
2011-02-26 21:55:59
StartTokkul - EndTokkul == TokkulGained.
;)
cause
2011-02-26 21:56:49
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.
lordsaturn
2011-02-26 21:57:02
From: 05hartor
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?
Yes, there is. Under function list, TPA -> AverageTIA.
HarryJames
2011-02-26 21:59:42
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!
i luffs yeww
2011-02-26 22:44:56
There's no real like.. graph functions, afaik, but it's not that difficult. Plot it and then draw lines from point to point.
Echo_
2011-02-27 08:57:02
You could try working off of this script for your graphing function, it looks challenging though.
http://villavu.com/forum/showthread.php?t=36548Otherwise, 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.
HarryJames
2011-02-27 10:23:31
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.