mIRC Homepage

Search for more then one var ?

Posted By: WarlockW

Search for more then one var ? - 08/10/05 01:56 AM

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 ..
Posted By: mIRCManiac

Re: Search for more then one var ? - 08/10/05 02:14 AM

/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
Posted By: WarlockW

Re: Search for more then one var ? - 08/10/05 04:36 AM

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)
Posted By: Om3n

Re: Search for more then one var ? - 08/10/05 05:51 AM

The correct syntax for unsetting a variable is unset %varname
Posted By: Kelder

Re: Search for more then one var ? - 08/10/05 10:54 AM

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)
Posted By: WarlockW

Re: Search for more then one var ? - 08/10/05 02:47 PM

hash table works great ..
thanks ..
never played with them yet till now :P

Thanks For the Help Guys smile
© 2022 mIRC Discussion Forums