Just a simple Question

For questions relating to POL scripting (not necessarily related to WoD)

Moderators: Siobhan, Sebastian, Drocket

Just a simple Question

Postby Rena on Wed May 05, 2004 5:36 am

Question?

Is there a way to find the highest number in a file, for instance:

Element 1234567
{
Rating i402
}

Element 7654321
{
Rating i622
}

In the two pieces of information above, is there a way to find the highest number out of those two ratings? And if so, is there a script I could reference?
Rena
Newbie
 
Posts: 11
Joined: Thu Jul 03, 2003 8:02 pm

Postby Drocket on Wed May 05, 2004 5:51 am

Yep, its quite possible, though its slightly complicated. First, though, if you've created the file specifically for POL, you shouldn't put the 'i' in the Rating. If you're stuck with it (imported the file from something else...) then you can work around it.

The general code that you'd want would look something like the following (warning: Untested code thrown together on the spur of the moment)

Code: Select all
use uo;
use os;
use cfgfile;

program check_ratings (character, text)  //assuming its a dot command
var rating_cfg := ReadConfigFile ("File name here");//the file you're importing needs to be a .cfg file, located in a POL-accessible package.
if (!rating_cfg)
SendSysMessage (character, "Unable to find file!");
return
endif

var keys := GetConfigIntKeys (rating_cfg) //Use GetConfigStringKeys if some of the keys are strings)
var highest_rating := 0;
var hightest_rating_key := 0;

foreach key in keys
   var theelem := GetConfigElem (rating_cfg, key);
   if (theelem and theelem.rating)
      if (theelem.rating > highest_rating)
         highest_rating := theelem.rating;
         highest_rating_key := key;
      endif
   endif
endforeach

SendSysMessage (character, "The highest rating was " + highest_rating + " in element " + highest_rating_key);

endprogram


If the 'i' has to stay there, then replace the 'foreach' section with something like:

Code: Select all
foreach key in keys
   var theelem := GetConfigElem (rating_cfg, key);
   var elemrating := theelem.rating;
   elemrating["i"] := "";
   elemrating := CINT (elemrating);
   if (elemrating)
      if (elemrating > highest_rating)
         highest_rating := elemrating;
         highest_rating_key := key;
      endif
   endif
endforeach
Drocket
Site Admin
 
Posts: 820
Joined: Mon Oct 07, 2002 2:54 am

Postby Rena on Sat May 08, 2004 1:35 am

Well Drocket, you are a godsend, I have but one more question, how hard would it be to have it read the top three ratings in the file? Oh man, got to make things more complicated dont I? Anyways, if you could help me on this one, I would be most thankful.
Rena
Newbie
 
Posts: 11
Joined: Thu Jul 03, 2003 8:02 pm


Return to Scripting Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron