mIRC Home    About    Download    Register    News    Help

Print Thread
Need help with this code #193906 27/01/08 03:23 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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" ?

Re: Need help with this code [Re: Tomao] #193911 27/01/08 06:26 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

Re: Need help with this code [Re: genius_at_work] #193912 27/01/08 06:51 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I'm afraid nothing shows.

Re: Need help with this code [Re: Tomao] #193950 27/01/08 05:26 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

Re: Need help with this code [Re: genius_at_work] #193991 27/01/08 10:44 PM
Joined: Apr 2006
Posts: 464
O
OrionsBelt Offline
Fjord artisan
Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Doesnt that if statement require brackets?


...nvm, works fine without, so I guess not.

Last edited by OrionsBelt; 27/01/08 10:46 PM.
Re: Need help with this code [Re: OrionsBelt] #193995 27/01/08 11:33 PM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
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

Re: Need help with this code [Re: hixxy] #194010 28/01/08 01:28 AM
Joined: Apr 2006
Posts: 464
O
OrionsBelt Offline
Fjord artisan
Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Thanks for the explanation hixxy

Never knew that was possible

Re: Need help with this code [Re: OrionsBelt] #194011 28/01/08 02:03 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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


Invision Support
#Invision on irc.irchighway.net
Re: Need help with this code [Re: Riamus2] #197216 31/03/08 12:50 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline
Babel fish
Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
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 
  }
}

Last edited by ots654685; 31/03/08 02:57 PM.
Re: Need help with this code [Re: ots654685] #197295 01/04/08 04:34 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline
Babel fish
Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
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

Last edited by ots654685; 01/04/08 04:35 PM.
Re: Need help with this code [Re: ots654685] #197298 01/04/08 06:21 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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...

Re: Need help with this code [Re: Tomao] #197329 02/04/08 07:39 AM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline
Babel fish
Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
@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