Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-14-2006, 02:28 PM
Snakeandy7 Snakeandy7 is offline
"Member ID=2610"
Snakeandy7's Avatar
Join Date: Mar 2003
Posts: 987
Snakeandy7 is on a distinguished road
My little problemo!

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:
HTML Code:
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:
HTML Code:
MaxDonater=3003,Raeiphon
MaxSecondDonater=3003,Raeiphon
money-Raeiphon=3003
money-Venom_Fish=102
money-xAndrewx=113
Overall_money=496782
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]
__________________
"Freedom is best I tell thee
of all things to be won
then never live within the bond
of slavery my son".


Reply With Quote
  #2  
Old 07-14-2006, 09:55 PM
upsilon upsilon is offline
Shmoo
upsilon's Avatar
Join Date: Dec 2005
Location: Birmingham, Alabama
Posts: 58
upsilon is on a distinguished road
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:
NPC Code:

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.
__________________
Health nuts are going to feel really stupid someday, lying in hospitals dying of nothing. - Redd Foxx

Last edited by upsilon; 07-14-2006 at 10:40 PM..
Reply With Quote
  #3  
Old 07-15-2006, 12:03 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
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...
__________________

Last edited by xAndrewx; 07-15-2006 at 12:15 PM..
Reply With Quote
  #4  
Old 07-16-2006, 02:51 AM
upsilon upsilon is offline
Shmoo
upsilon's Avatar
Join Date: Dec 2005
Location: Birmingham, Alabama
Posts: 58
upsilon is on a distinguished road
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.
__________________
Health nuts are going to feel really stupid someday, lying in hospitals dying of nothing. - Redd Foxx

Last edited by upsilon; 07-16-2006 at 03:04 AM..
Reply With Quote
  #5  
Old 07-16-2006, 10:15 AM
Snakeandy7 Snakeandy7 is offline
"Member ID=2610"
Snakeandy7's Avatar
Join Date: Mar 2003
Posts: 987
Snakeandy7 is on a distinguished road
I see, thank you
__________________
"Freedom is best I tell thee
of all things to be won
then never live within the bond
of slavery my son".


Reply With Quote
  #6  
Old 07-17-2006, 01:38 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
Don't call index 0 NULL, because it's not... FYI.
Reply With Quote
  #7  
Old 07-18-2006, 12:29 AM
ForgottenLegacy ForgottenLegacy is offline
-Backtoscripts-
Join Date: Aug 2003
Location: California
Posts: 289
ForgottenLegacy is on a distinguished road
Send a message via AIM to ForgottenLegacy
Erm, problem.

if (0 == NULL) {

that returns true.
__________________
"The higher you fly, the harder it is to breathe."

[Kaidenn] Maybe I will somehow take control of Lance's body when he isn't looking, have him log onto Kingdoms, update one script, and leave.
[Kaidenn] And leave him exactly where I found him, unchanged and completely unnaware of what just took place the last two minutes.
[GrowlZ] Lance: You might want to lock your bedroom door tonight
Reply With Quote
  #8  
Old 07-18-2006, 12:52 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
0 == false == "" == null == "0"
Reply With Quote
  #9  
Old 07-18-2006, 08:38 AM
ForgottenLegacy ForgottenLegacy is offline
-Backtoscripts-
Join Date: Aug 2003
Location: California
Posts: 289
ForgottenLegacy is on a distinguished road
Send a message via AIM to ForgottenLegacy
x_____________________________________________X SOMEONE FIX THIS PL0X

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

Graal should be like that
__________________
"The higher you fly, the harder it is to breathe."

[Kaidenn] Maybe I will somehow take control of Lance's body when he isn't looking, have him log onto Kingdoms, update one script, and leave.
[Kaidenn] And leave him exactly where I found him, unchanged and completely unnaware of what just took place the last two minutes.
[GrowlZ] Lance: You might want to lock your bedroom door tonight
Reply With Quote
  #10  
Old 07-18-2006, 04:29 PM
upsilon upsilon is offline
Shmoo
upsilon's Avatar
Join Date: Dec 2005
Location: Birmingham, Alabama
Posts: 58
upsilon is on a distinguished road
Quote:
Originally Posted by ForgottenLegacy
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.
__________________
Health nuts are going to feel really stupid someday, lying in hospitals dying of nothing. - Redd Foxx

Last edited by upsilon; 07-18-2006 at 08:54 PM..
Reply With Quote
  #11  
Old 07-18-2006, 08:24 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by ForgottenLegacy
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".
__________________
Skyld
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.