mIRC Home    About    Download    Register    News    Help

Print Thread
Search for more then one var ? #132174 08/10/05 01:56 AM
Joined: Jan 2004
Posts: 133
W
WarlockW Offline OP
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
wana see if there is a way to search
for more then one var ..

if ( $nick == %list* )

%list1 tom
%list2 mike
%list3 greg
%list4 mark

Have it check all vars with list in it for the nick
Something like that ?

Thaks ..

Re: Search for more then one var ? #132175 08/10/05 02:14 AM
Joined: Feb 2005
Posts: 681
M
mIRCManiac Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Feb 2005
Posts: 681
/help $var

$var(%list*,1)
$var(%list*,2)
$var(%list*,3)
$var(%list*,4)

alias listtest {
var %i = 1
while ($var(%list*,%i) != $null) {
if ($eval($v1,2) == $1) {
echo -a Found $v1
return
}
inc %i
}
echo -a $1 not found.
}

type //set %list1 tom | set %list2 mike | set %list3 greg | set %list4 mark

type /listtest mike
type /listtest albert

Last edited by mIRCManiac; 08/10/05 02:26 AM.
Re: Search for more then one var ? #132176 08/10/05 04:36 AM
Joined: Jan 2004
Posts: 133
W
WarlockW Offline OP
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
Cool .. Now what if i wana del that var it finds

So if it finds: MIKE and would del : %list2 mike

alias listtest {
var %i = 1
while ($var(%list*,%i) != $null) {
if ($eval($v1,2) == $1) {

unset var = %list2

return
}
inc %i
}
echo -a $1 not found.
}


Thanks smile)

Re: Search for more then one var ? #132177 08/10/05 05:51 AM
Joined: Jul 2003
Posts: 655
Om3n Offline
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
The correct syntax for unsetting a variable is unset %varname


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Re: Search for more then one var ? #132178 08/10/05 10:54 AM
Joined: Apr 2003
Posts: 701
K
Kelder Offline
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Often when you need to do something tedious like checking a list of variables for a match, it's better to stop and think about what you are doing and if you have the most appropriate data structure to do it.

In this case, instead of %list1 = joe, %list2 = bob, list3 = jim, you could:
-> put all nicks in a single var
set %nicklist joe jim bob
if ($istok(%nicklist,$nick,32)) { echo yep, $nick is found }

-> make an ini file
[nicknames]
joe = 1
bob = 1
jim = 1
if ($readini(nicks.ini,nicknames,$nick)) { echo yep, $nick is found }

-> make a hash table
hmake nicks 10
hadd nicks joe 1
hadd nicks jim 1
hadd nicks bob 1
if ($hget(nicks,$nick)) { echo yep, $nick is found }

Each has it's own advantages and disadvantages, the key to being a good scripter is choosing the option that suits best, not in this case, but combined over all other uses of this data (list of nicknames here)

Re: Search for more then one var ? #132179 08/10/05 02:47 PM
Joined: Jan 2004
Posts: 133
W
WarlockW Offline OP
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
hash table works great ..
thanks ..
never played with them yet till now :P

Thanks For the Help Guys smile