|
mugsi
|
mugsi
|
Hi, i beg for some help, ive made a scrip which compares all vars of type test_* and returns the first [given number] variable names wich own the highest values. what is returned looks like test_XXX, test_GGG, test_LLL. I want to filter the "test_" thing so the output will look like XXX, GGG, LLL. any suggestions ?
|
|
|
|
Joined: Apr 2004
Posts: 755
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 755 |
what ? If you request something, make sure that whomever you ask it to gets what you are saying. Can you paste any relevant code and try to formulate your question in a better way? Theres loads of friendly helpers on the forum all wanting to help you, but in order to help you we first need to know the problem 
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
These two aliases will help you create an efficient solution to your problems. alias scores_make {
window -h @scores
clear @scores
var %i = 1
while ($var(%test_*,%i)) {
aline @scores $gettok($v1,2,95) $($v1,2)
inc %i
}
filter -wwctue 2 32 @scores @scores
}
[color:red] [/color]
alias scores_show {
[color:red] [/color]
; /scores_show <N> [command]
; if N = 0, it shows them all
[color:red] [/color]
if ($1 !isnum 0-) || (!$window(@scores)) return
var %i = 1, %ii = $iif($1,$1,$line(@scores,0)), %cmd = $iif($3,$3-,echo -a)
while (%i <= %ii) && ($line(@scores,%i)) {
%cmd %i - $v1
inc %i
}
} (code requires mIRC 6.16)
|
|
|
|
sazeMaster
|
sazeMaster
|
why don't you simple put the three numbers INTO the var instead of attach them to the var names?
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
They are in the var.
I think he has something like:
%test_jake 45 %test_jane 12 %test_jason 100 ...
He wants to get the names (jake, jane, jason, ...) with the highest value for score, which are the values of the variables, atleast so I think.
|
|
|
|
mugsi
|
mugsi
|
sry, its true that the question was not well formulated. Im no native english speaker and by the time i posted it i was too stoned to write it better, sry again. really appreciate ur help. what i'm trying to do here is a simple statistics module that logs how many times a specified user has executed a command. Hits are stored in variables like %test_nickname. Reading the top scores is done by the following script :
alias top {
var %i = $var($1,0),%r,%n = 1,%t = $iif($prop isnum,$prop,5),%d
while (%i) { set -u0 % $+ $($var($1,%i),2) $var($1,%i) | %r = %r $($var($1,%i),2) | dec %i }
%r = $sorttok(%r,32,nr) | tokenize 32 %r
while (%n <= %t) && ($($ $+ %n,2)) { %d = $addtok(%d,$(% $+ $($ $+ %n,2),2),44) | inc %n }
return %d
}
and called using $top(var*).N where N is the number of nicks to be put in a channel. Example
say $chan module stats TOP $1 $top(test_*). [ $+ [ $1 ] ]
As output for $top(test_*).3 comes %test_nick1, %test_nick2, %test_nick3 What i havent figured out how to do is to take this string "%test_nick1, %test_nick2, %test_nick3" and substract all "%test_". Is it clear now ?
Last edited by mugsi; 15/12/05 02:19 PM.
|
|
|
|
Joined: Apr 2004
Posts: 755
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 755 |
return $remove(%d,%,test_) ??
I have to warn you though that you method will become flaw once %r starts to be more then mIRC's 940 character limit. Examin the methods provided to you by FiberOPtics as those overcome this problem.
Enjoy
|
|
|
|
mugsi
|
mugsi
|
omfg, damn noob i am i was searching ages in the help file for such thing as $remove and missed it  (((( sry, post was pointeless, anyway thx for enlightening me.
Last edited by mugsi; 15/12/05 02:33 PM.
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
If you would have taken the time to actually examine my code you would have seen the following line:
aline @scores $gettok($v1,2,95) $($v1,2)
Which actually should have had range 2-, but I didn't think of it at the time.
However, using $gettok or $remove has important shortcomings.
For remove: if you have a nickname that contains the string "test_" in it, it will remove that as well, corrupting the nickname.
For $gettok: will remove the first and trailing delimiters, $gettok(____test____,1-,95) = test
Your best bet could be to use a simple $mid like:
//echo -a $mid(% $+ test__tester_nick__,7)
|
|
|
|
mugsi
|
mugsi
|
cheers
ill revisit ur code and maybe use it instead of mine
|
|
|
|
mugsi
|
mugsi
|
actually i've done it like this. ive added a "#" to the beginning of the var name so it now it looks like #test_. Since a nickname containing # is an Erroneous Nickname (so nickname like test_ or somethingtest_123 wont be corrupted). return $remove(%d,%,#stat_) works perfectly.
Last edited by mugsi; 15/12/05 03:33 PM.
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
Sure that works as well. I just gave you a solution that doesn't require for you to rename your already existing variables. The $mid(<var>,7) will work 100% correct without having to do any changes.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
There is a problem with your code. (I did change to $mid) If you don't give anything for $1, it doesn't show anything. I altered these lines:
if (!$window(@scores)) return
var %i = 1, %ii = $iif([color:red]$1 isnum 0-[/color],$1,$line(@scores,0)), %cmd = $iif($3,$3-,echo -a)
-genius_at_work
|
|
|
|
Joined: Apr 2004
Posts: 755
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 755 |
I wouldnt call it a problem it does say N is a manditory parameter and $null != 0 , so it not returning anything is expected.
i do however think %cmd = $iif($3,$3-,echo -a) should be %cmd = $iif($2,$2-,echo -a)
if the syntax is <N> [command]
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
Indeed it should be $2- instead of $3- wow I've been out partying till 4 am I'm veru very drunk damn,;...
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
; /scores_show <N> [command] ; if N = 0, it shows them all
What are you talking about? If you don't specify anything, then it isn't supposed to show anything, because I have clearly stated, and the code clearly shows this with the isnum 0- check that the first parameter must be a number that is either zero or higher. When taking a closer look at the $iif, you clearly notice that when you specify a 0, it will show all entries, if you specify a positive N it will show the N'th score. $iif($1,$1,$line(@scores,0)) is exactly like I intended it. If you specify 0, then the $iif is false, so it must loop from 1 till the end, therefore %ii is assigned $line(@scores,0) With your isnum check, when specifying a 0, it would not show anything, because %ii would be set zero. Of course it doesn't return anything, did you even bother to take a look at the code?!? if ($1 !isnum 0-) || (!$window(@scores)) return
Last edited by Merlin; 15/01/06 08:40 AM.
|
|
|
|
|