View Full Version : My little problemo!

07-14-2006, 03:28 PM
I'm having a few problems. I've created a minor event thing on Era, You donate money to a guy, which adds the
''this.MaxDonater (money, amount)''
It all works, however, when trying to find out who has done the second most donated money, it causes a few problems...

Here's the script:

public function ShowBridgeStats()
//The most money donated
echo(format(_("Most money donated: %s ($%d)"),
this.MaxDonater[1], this.MaxDonater[0]));

temp.check = getflagkeys(this.money-);
for (temp.i = 0; temp.i < temp.check.size(); temp.i++)

//Error down here vv
if (this.("money-" @ temp.check[temp.i]) < this.MaxDonater[0])
if (temp.check[temp.i] != this.MaxDonater[1] &&
temp.OldAccount != this.MaxDonater[1])
if (this.("money-" @ temp.check[temp.i]) < this.("money-" @ temp.OldAccount))
this.MaxSecondDonater = {this.("money-" @ temp.OldAccount), temp.OldAccount};
//Error up here^^

temp.OldAccount = temp.check[temp.i];

//The second max donator...
echo(format(_("2nd most money donated: %s ($%d)"),
this.MaxSecondDonater[1], this.MaxSecondDonater[0]));

And some flag's from the NPC:


As you can see, the second max donater is actually the first one.
It's probably a simple thing I am missing, but I can't seem to find it. If anyone could help, it'd be great, thanks!
[I used a public function to call it from another NPC]

07-14-2006, 10:55 PM
I think its only coincidence that they are the same, and only coincidence that they are the greatest donation.

That doesnt not calculate the greatest value of them all. It repeatedly sets the MaxSecond var to the latter of any two pairs of values if the latter is the largest. Nothing is ever compared with MaxSecond, so there is no reason to think that the last value of MaxSecond is actually the largest of all the values ever assigned to in the iteration.

I say you just toss out whatever code you have for calculating the two, and rewrite it.

I dont see the Maximum value being calculated here, so maybe theres a chance its being calculated after this, which would be the same as if the check in this one didnt even exist.

No insult intended, but that code makes absolutely no sense.

Here, this may help:

function maxDonation(donations) {
enum { amount,name };
temp.largest = donations[0]; //need a starting point
for(temp.i = 1; temp.i < donations.size(); temp.i++) { //notice the count starts at 1
temp.current = donations[temp.i];
if (temp.current[amount] > temp.last[amount]) { //if the largest is not larger than the current donation....
temp.largest = temp.current; //update accordingly
} //if
} //for
return temp.largest;
} //function

now, to calculate the largest and second largest, you only have to do a couple things:
1) pair the amounts and the names in a list; amounts first, names second.
2) assign the result of passing this list to the function above, to the MaxDonater variable
3) remove MaxDonater from the list.
4) assign the result of applying the function to the newly updated list to MaxSecondDonater. MaxDonater isnt in the list, so it cant be duplicated in MaxSecondDonater

hope this helps.

07-15-2006, 01:03 PM
I don't quite understand your code at all to be honest.
An array starts at the NULL position (0), not at one...
If you started it at one, then you would compleatly miss
the first param in the array.

I'll give it a go though, thanks...

07-16-2006, 03:51 AM
Well, there needs to be something in the temp.largest variable before the loop starts. On line 3, the first item in the array is dumped into it, and there isnt much point in starting the loop off at 0, since youd just be comparing the first value with its self. It also allows for cases where there is only one donator, donators.size() will be equal to 1, so the loop will be skipped, and the first and only item in the array is returned.

07-16-2006, 11:15 AM
I see, thank you

07-17-2006, 02:38 AM
Don't call index 0 NULL, because it's not... FYI.

07-18-2006, 01:29 AM
Erm, problem.

if (0 == NULL) {

that returns true.

07-18-2006, 01:52 AM
0 == false == "" == null == "0"

07-18-2006, 09:38 AM
x_____________________________________________X SOMEONE FIX THIS PL0X

0 == "0", true
0 == false, true
0 != NULL
0 != ""

Graal should be like that

07-18-2006, 05:29 PM
Erm, problem.

if (0 == NULL) {

that returns true.

But its meaningless to call it the NULL index; like calling index 1 the 'true' index, or index 3 the floor(pi) index. Not that its all that important what you call it, as long as people know what you are talking about.

07-18-2006, 09:24 PM
x_____________________________________________X SOMEONE FIX THIS PL0X

0 == "0", true
0 == false, true
0 != NULL
0 != ""

Graal should be like that
I have three words. "Old engine compatibility".