mIRC Home    About    Download    Register    News    Help

Print Thread
split a string #137588 15/12/05 08:35 AM
Joined: Dec 2005
Posts: 5
M
mugsi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2005
Posts: 5
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 ?

Re: split a string #137589 15/12/05 11:57 AM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
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 smile


$maybe
Re: split a string #137590 15/12/05 12:45 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
These two aliases will help you create an efficient solution to your problems.

Code:
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)


Gone.
Re: split a string #137591 15/12/05 12:46 PM
Joined: Nov 2003
Posts: 32
S
sazeMaster Offline
Ameglian cow
Offline
Ameglian cow
S
Joined: Nov 2003
Posts: 32
why don't you simple put the three numbers INTO the var instead of attach them to the var names?

Re: split a string #137592 15/12/05 12:52 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
Re: split a string #137593 15/12/05 02:16 PM
Joined: Dec 2005
Posts: 5
M
mugsi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2005
Posts: 5
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 :
Code:
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
Code:
 
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.
Re: split a string #137594 15/12/05 02:25 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
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


$maybe
Re: split a string #137595 15/12/05 02:32 PM
Joined: Dec 2005
Posts: 5
M
mugsi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2005
Posts: 5
omfg, damn noob i am
i was searching ages in the help file for such thing as $remove and missed it frown((((

sry, post was pointeless, anyway thx for enlightening me.

Last edited by mugsi; 15/12/05 02:33 PM.
Re: split a string #137596 15/12/05 02:45 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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)


Gone.
Re: split a string #137597 15/12/05 02:50 PM
Joined: Dec 2005
Posts: 5
M
mugsi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2005
Posts: 5
cheers

ill revisit ur code and maybe use it instead of mine

Re: split a string #137598 15/12/05 03:18 PM
Joined: Dec 2005
Posts: 5
M
mugsi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2005
Posts: 5
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.
Re: split a string #137599 15/12/05 03:34 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
Re: split a string #137600 15/12/05 07:28 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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:
Code:
  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

Re: split a string #137601 15/12/05 07:56 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
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]


$maybe
Re: split a string #137602 16/12/05 03:02 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Indeed it should be $2- instead of $3- wow I've been out partying till 4 am I'm veru very drunk damn,;...


Gone.
Re: split a string #137603 14/01/06 07:10 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Quote:

; /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?!?

Quote:

if ($1 !isnum 0-) || (!$window(@scores)) return

Last edited by Merlin; 15/01/06 08:40 AM.