mIRC Homepage
Posted By: tabby BIGGER SORT!! HELP0Rz! - 26/03/05 03:18 AM
Ok, my mIRC bot i am making a 'news service' type thing, in a hash table 'news' i have

$ctime news:information
$ctime news:inforamtion
$ctime news:information

etc. Because hash tables are like they are, when i go to output the data ie /msg mybot newslist i obviously want to list it in order of date sent so i do a loop of the hash table, and wack every item into a %var ie

$ctime:$ctime:$ctime:$ctime

then i use $sorttok on the %var and then do a loop on the %var to get the right time etc.

BUT when there is 60 or more im getting * set line too long ... is there any other way i can make it work or make a sorting process that will kinda work exactly the same that will allow me to have like up to well like 500 or something smirk

Thankyou!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Posted By: tidy_trax Re: BIGGER SORT!! HELP0Rz! - 26/03/05 03:23 AM
You can dump everything into an @window opened with the -s switch and the data will be automatically sorted. Just make sure you use /aline and not /echo to add the data.
Posted By: tabby Re: BIGGER SORT!! HELP0Rz! - 26/03/05 03:56 AM
Silly me, i'll tell you how it goes :-)
Posted By: tabby Re: BIGGER SORT!! HELP0Rz! - 26/03/05 04:03 AM
hmmm

/window -s @news
/aline @news 1
/aline @news 20
/aline @news 5

in the window:

1
20
5

doesn't seem to sort it :-\
Posted By: Relinsquish Re: BIGGER SORT!! HELP0Rz! - 26/03/05 05:04 AM
The -s switch sorts the window alphabetically, not numerically. Thus, you will have to use /filter to alphabetically and numerically sort the window.

Code:
/filter -ctu 1 32 @news @news
Posted By: tabby Re: BIGGER SORT!! HELP0Rz! - 26/03/05 05:31 AM
i just used

/filter -a @news @news1 routine_filter

alias routine_filter { return $iif($1 > $2,1,$iif($1 < $2,-1,0)) }

probably did the long way ? :-)
Posted By: Relinsquish Re: BIGGER SORT!! HELP0Rz! - 26/03/05 05:39 AM
The -tu switches are a lot faster than calling an alias to sort the lines. The command I showed you should work without any problems.
Posted By: DaveC Re: BIGGER SORT!! HELP0Rz! - 26/03/05 07:31 AM
This well be fine for his application

/window -s @news

$ctime is a 10 digit number and has been for some time
Posted By: tidy_trax Re: BIGGER SORT!! HELP0Rz! - 26/03/05 01:02 PM
Yep, the -s switch to sort $ctime values will be fine for a good few years :[/b]o)
Posted By: Kelder Re: BIGGER SORT!! HELP0Rz! - 26/03/05 02:17 PM
Is there a reason why you're not just using sequence numbers? Something like this:

alias news_init {
hmake news 10
set %news.lb 1
set %news.ub 1
}
alias news_addentry {
inc %news.ub
hadd news %news.ub $ctime $1- (whatever you want to enter)
}
alias news_remove_oldest_entry {
hdel news %news.lb
inc %news.lb
}
alias news_list {
var %k = %news.lb
while (%k <= %n) {
var %news = $hget(news,%k)
echo @newswindow Time: $gettok(%news,1,32) Text: $gettok(%news,2-,32)
inc %k
}
}

No need to sort stuff each time you need to send or display the news items. Only bad points: putting a news item in between is not easy (requires all following news entries to be moved) and searching on $ctime is somewhat more time-consuming, use $hfind(news,$ctime *,1,w).data to get the correct sequence number.

I've used global %variables for lower and upper bound, you can also put them in the hash table itself ofcourse...
© mIRC Discussion Forums