mIRC Homepage
Posted By: Tomao Need help with this code - 27/01/08 03:23 AM
Code:
alias checkk {
  var %a = 1,%lev = $iif($1,$1,*)
  while $ulist(*,%lev,%a) {
    echo 4 -a -> %a $+($level($v1),:,$v1)
    inc %a 
  }
}


I use the code above to scan what I have in users list, but how do you make it tell you there's nothing added in it using "else" ?
Posted By: genius_at_work Re: Need help with this code - 27/01/08 06:26 AM
Try this:

Code:

alias checkk {
  var %a = 1,%lev = $iif($1,$1,*)
  if ($ulist(*,%lev,%a) == 0) echo 4 -a -> 0 results
  while $ulist(*,%lev,%a) {
    echo 4 -a -> %a $+($level($v1),:,$v1)
    inc %a 
  }
}



-genius_at_work
Posted By: Tomao Re: Need help with this code - 27/01/08 06:51 AM
I'm afraid nothing shows.
Posted By: genius_at_work Re: Need help with this code - 27/01/08 05:26 PM
Code:

alias checkk {
  var %a = 1,%lev = $iif($1,$1,*)
  if ($ulist(*,%lev,0) == 0) echo 4 -a -> 0 results
  while $ulist(*,%lev,%a) {
    echo 4 -a -> %a $+($level($v1),:,$v1)
    inc %a 
  }
}



-genius_at_work
Posted By: OrionsBelt Re: Need help with this code - 27/01/08 10:44 PM
Doesnt that if statement require brackets?


...nvm, works fine without, so I guess not.
Posted By: hixxy Re: Need help with this code - 27/01/08 11:33 PM
You can get away with not using { } if there's only one command to perform.

The main thing to watch out for is this:

Code:
if (x) echo -a this triggers when the if is $true | echo -a this triggers no matter what, whilst some would expect it to trigger only if the if was $true
Posted By: OrionsBelt Re: Need help with this code - 28/01/08 01:28 AM
Thanks for the explanation hixxy

Never knew that was possible
Posted By: Riamus2 Re: Need help with this code - 28/01/08 02:03 AM
It's possible, and has been said to be faster. However, I personally find it harder to read quickly. I'd rather see the {}'s used appropriately than not, but that's just my personal preference. At the same time, I don't overdo the ()'s in IF's.

if (this == that && that == this) {}

instead of

if (this == that) && (that == this) {}

or

if ((this == that) && (that == this)) {}


I'll only add the extra ()'s when order of operation is needed. Again, just my personal preference. smile
Posted By: ots654685 Re: Need help with this code - 31/03/08 12:50 PM
Nice piece of code, could come in handy here but have 1 question about it.
It fit's more situations but ok.
I never understood the loop mechanism and i'm trying to strip the output of this snippet.
Fixed.

Code:
alias checkk {
  var %a = 1
  if ($ulist(*,0) == 0) echo 4 -a -> 0 results
  while $ulist(*,%a) {
    echo @users -> %a $v1
    inc %a 
  }
}
Posted By: ots654685 Re: Need help with this code - 01/04/08 04:34 PM
After playing with this and modified it i noticed using levels is more handy for me but i can't manage to get out put sorted:
now it gives me this
-> 1 group1:user1!*user1@localhost
-> 2 group2:user4!*user4@localhost
-> 3 group2:user5!*user5@localhost
-> 4 group1:user2!*user2@localhost
-> 5 group1:user3!*user3@localhost
-> 6 group2:user6!*user6@localhost

But i would like to see something like this
group1
user1
user2
user3

group2
user4
user5
user6

Last part of <useraddress> (!*user6@localhost) is need for script but not needed in output but i don't know how to strip that.

More simple would be sorting user.ini and give that as output but i'm trying to understand current piece of code and extend it with other options
Posted By: Tomao Re: Need help with this code - 01/04/08 06:21 PM
Code:
alias checkk {
  var %a = 1,%lev = $iif($1,$1,*)
  if ($ulist(*,%lev,0) == 0) echo 5 -a -> 0 results
  while $ulist(*,%lev,%a) {
    echo 6 -a -> User $+ $remove(%a,$null)$+($level(!$v1),$v1))
    inc %a 
  }
}


This might do the trick. I can get User1, User2, User3 etc...
Posted By: ots654685 Re: Need help with this code - 02/04/08 07:39 AM
@Tomao:
That does the trick for sorting but still struggling with sorting it by group

echo output:
group1
user1
user2
user3

group2
user4
user5
user6

Thanks for helping anyway
© mIRC Discussion Forums