mIRC Home    About    Download    Register    News    Help

Print Thread
#198355 27/04/08 03:33 AM
Joined: Sep 2007
Posts: 109
K
kwell Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
I'm doing wrong the alias

Code:
on !*:TEXT:*:#: {
  if ($ulevel = 10) {
    $command(.op,+o) 
    $command(.deop,-o) 
  }
}
alias command {
  if ($strip($1) == $1) { .mode $chan $2 $nick }
}


The problem is in $strip($1) == $1 ?

kwell #198356 27/04/08 03:38 AM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Nevermind I miss read your script.

I see what your trying to do now

The reason why your $command alias is not working is because $chan and $nick is not recongnized in the alias, you would have to create a var or call the channel from $active.

and for the nick it needs to be stores in the var, thats why your .mode $chan $2 $nick is not working.

example

alias command {
if ($strip($1) == $1) { .mode $active $2 %nick }
}

would work if the channel in question you were active on...

but

alias command {
if ($strip($1) == $1) { .mode %chan $2 %nick }
}

would work wherever the command is triggered..

so in your on text event create a var like this

%chan = #
%nick = $nick

so you can use it in your alias.

Also the $ulevel check doesnt need to be done you can do this

Code:
on 10:TEXT:*:#: {
%chan = $chan
%nick = $nick
    $command(.op,+o) 
    $command(.deop,-o) 
}
alias command {
  if ($strip($1) == $1) { .mode %chan $2 %nick }
}


Then again your script seems to be calling $command twice which leaves the use of the alias almost pointless.

But ill leave u be with it


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Lpfix5 #198357 27/04/08 04:59 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Alternative suggestion
Code:
on @10:TEXT:*:#: {
  $command($chan,$nick,$1,op,deop)
}
alias command {
  if $strip($3) == $3 {
    .mode $1 $iif($5 isin $3,-o,$iif($4 isin $3,+o)) $2
  }
}

Lpfix5 #198367 27/04/08 12:02 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
The reason why your $command alias is not working is because $chan and $nick is not recongnized in the alias, you would have to create a var or call the channel from $active.

As was pointed out to RussellB in this thread, remote identifiers like $nick, $chan etc are recognized in aliases. So passing them as parameters to an alias is not only redundant and wasteful but makes the code less readable (it's harder to keep track of what each parameter is in the alias). Storing them to global vars does not have the latter problem, but it is still redundant and even more wasteful.

As I said recently in another thread, if you are not absolutely sure that the error is indeed where you think it is, please do not make assertive statements before actually testing it yourself. Saying "it may be that remote identifiers don't work in aliases" would have been OK (although actually testing it and giving the correct answer would be even better). Making it sound like a fact and that you know what you're talking about is misleading to new users, sending them on a wild goose chase.

I'm also surprised that nobody pointed out that custom identifiers are not meant to be used as commands. In this particular case, $command works because it doesn't return anything. If it did, there would be errors, since mirc would try to execute the return value of $command. It would be nice if helpers (especially the ones with apparent experience, aka post count) did not just try to fix the OP's particular problem but also give guidelines on good practice. Among other things, this could help prevent future errors.

Regarding the OP's problem:
Code:
on @10:TEXT:*o*p*:#:{
  var %cmd = $strip($1)
  if (%cmd == .deop) mode # -o $nick
  elseif (%cmd == .op) mode # +o $nick
}

or if an alias must be used (eg if the above code is used in multiple places), and keeping it as close as possible to the OP's design:
Code:
on @10:TEXT:*o*p*:#:{
  command .op +o $1
  command .deop -o $1
}
alias command {
  if ($strip($3) == $1) mode # $2 $nick
}
These are still not perfect, as they don't check whether $nick already has the mode he requested, but that's another story.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #198372 27/04/08 02:57 PM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
SOrry I was drinking last night, frown please forgive me


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
qwerty #198373 27/04/08 03:14 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Originally Posted By: qwerty

It would be nice if helpers (especially the ones with apparent experience, aka post count) did not just try to fix the OP's particular problem but also give guidelines on good practice. Among other things, this could help prevent future errors.


I recall being accused of "trying to force my scripting style" on someone here some time ago because I not only helped with their problem, but also changed a few things in their script (added brackets to if statements, removed slashes from commands etc.). Some people here use some really crappy scripting practices themselves, so you know they're not going to try to educate otherwise.

~ Edit ~
Not that I think my own scripting is perfect, far from it lol.


Last edited by RoCk; 27/04/08 03:24 PM.
RoCk #198376 27/04/08 03:50 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
I meant practice in a functional way, something that could affect the correctness of the code. Slashes and brackets are mainly style, ie cosmetic features (although brackets can alter the way scripts are parsed). I see nothing wrong with a helper changing the original code to meet his own style: he is the one writing the code so naturally he will use his style. The OP can always change it back if he has a different style. What would be wrong in such cases is trying to pass this style as objectively better, alluding to potential functional differences.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #198377 27/04/08 04:06 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

I did explain that slashes are not only unnecessary, but the code looks cleaner without them, so yes cosmetic. With the brackets however, I mentioned that not using brackets will work in some situations but may not work in other situations, so why not just use them all the time? That's not cosmetic or personal preference, that's just common sense. Same goes with using the equals sign with the var command, why not just use it all the time for the same reasons as brackets in if statements? Also using pipes, it may work but can get confusing with multiple if-then-else statements and then when it doesn't work, it can get even more confusing trying to debug it. Most of it's just common sense really. Most times it seems people try to use the smallest code at the cost of good scripting practice, and I've caught myself doing it at times too when some script starts getting really long.


Link Copied to Clipboard