mIRC Homepage
Posted By: iStink Custom Operators. - 19/08/07 09:30 AM
I was thing about my scripts when i suggest this.
Anyway... {
My scripts are usually challenging, and simple... BUT: I like them to be clean. so i dont like to see the little boxes. instead I use $+($chr(3),03) I don't use $+ alone. it must have multiple paramaters for me to even use $+ smile
Anyway!! To the point {
The custom operator would be nice versus using an alias like: $iif(isowner $nick $chan,,)
you could use $iif($nick isowner $chan)
I've been thinking about it and my buddies think its a great idea.
the operators could be stored in their own tab on the scripts editor, and they could have the option in the remotes section (where you can put everything lol)
would be an example of:
Code:
operator isowner {
return $iif($nick(#,$nick).pnick == ~,$true,$false)
}
Posted By: RusselB Re: Custom Operators. - 19/08/07 10:39 AM
I thought I'd seen an isowner operator in the help file already, and that Khaled had mentioned that it only worked on certain types of networks, but I was unable to locate where I was getting this information from in order to confirm it.
Posted By: Horstl Re: Custom Operators. - 19/08/07 11:08 AM
Why don't simply use good old aliases to set this operation:
Code:
alias isowner { return $iif((~ isin $nick(#$2,$1).pnick),$true,$false) }
...and go on evaluating this "operation" in your script with:
Code:
if ($isowner($nick,$chan)) { stuff }
else { elsestuff }
or:
Code:
$iif(($isowner($nick,$chan)),ifstuff,elsestuff)


"if ($isowner($nick,$chan))" is as short as a hypothetical "if ($nick isowner $chan)", isn't it? smile

At first, I liked the idea of custom operators. But then: these operations can be scripted with ease (as shown above). Finally, there is a lot of "operations" we'd use in scripts that need more parameters than v1 and v2, imho here the use of aliased "operations" is inevitable smile

Aliases are far more flexible: $some_returning_alias(param1,param2,...,paramN).property_possible
Posted By: hixxy Re: Custom Operators. - 19/08/07 11:48 AM
I'd love to see this, but your way of doing things is a little odd. I'd prefer that we have access to $v1/$v2 from within the operator.

Code:
operator " { return $v1 $+ $v2 }


var %x = x " y

xy

Originally Posted By: Horstl
Why don't simply use good old aliases to set this operation:


The flow of using an alias within the script is not as logical:

if ($isowner($nick,$chan))

Reads (in my head): if isowner nick on chan

if ($nick isowner $chan)

Reads (again in my head): if nick isowner on chan

It's a lot more logical.
Posted By: Horstl Re: Custom Operators. - 19/08/07 11:58 AM
Originally Posted By: hixxy
Reads (in my head): if isowner nick on chan
Well, mine is reading "if isowner is true for nick on chan" smile
I did not want to dismiss the whole custom operator idea at all... I just cannot think of any crucial advantage so far
Posted By: hixxy Re: Custom Operators. - 19/08/07 12:03 PM
There isn't really, it's purely a syntax thing, although I imagine it'd be slightly faster to parse operators than it would identifiers.
Posted By: iStink Re: Custom Operators. - 19/08/07 01:51 PM
well, i dont like aliases and identifiers as much as i do operators, because they make scripts look cleaner. commas make scripts look sloppy (to me) and so does the rest of the 11k people who script on the swiftirc network, smile I'm saying that putting in more things that people want or would use, they would use the product better. and var %money = 11000 * 20
while (%money) noop
Posted By: starbucks_mafia Re: Custom Operators. - 19/08/07 02:33 PM
Even if custom operators were possible they would still need a prefix to distinguish them from ordinary text, otherwise you could end up with horrible problems like:
if (hello moo [color:red]newoperator %blah) ...[/color]
becoming
if (hello [color:red]moo newoperator %blah) ...[/color]
if a new script introduced a moo operator.

So with that in mind, is:
$iif($nick [color:red]$~isowner $chan)[/color]
(assuming $~ as the operator prefix) really much cleaner than
$iif($isowner($nick, $chan))

There are some uses to having custom operators, I just don't think saving a couple of commas is one of them.

Note 1: As RusselB mentioned, mIRC already has an undocumented operator isowner which works as expected on most networks that support it.

Note 2: If you call an alias in an event then all special identifiers (such as $nick and $chan) will be available to the alias too. So if you're really worried about commas you could write a custom identifier like this:
Code:
alias isowner {
  var %chan = $iif($2,$2,$chan), %nick = $iif($1,$1,$nick)
  return $iif($nick(%chan, %nick).pnick == ~, $true, $false)
}


and call it as:
Code:
if ($isowner) ...

inside events.
Posted By: iStink Re: Custom Operators. - 20/08/07 04:59 AM
Originally Posted By: starbucks_mafia
Even if custom operators were possible they would still need a prefix to distinguish them from ordinary text, otherwise you could end up with horrible problems like:
if (hello moo [color:red]newoperator %blah) ...[/color]
becoming
if (hello [color:red]moo newoperator %blah) ...[/color]
if a new script introduced a moo operator.

So with that in mind, is:
$iif($nick [color:red]$~isowner $chan)[/color]
(assuming $~ as the operator prefix) really much cleaner than
$iif($isowner($nick, $chan))

There are some uses to having custom operators, I just don't think saving a couple of commas is one of them.

Note 1: As RusselB mentioned, mIRC already has an undocumented operator isowner which works as expected on most networks that support it.

Note 2: If you call an alias in an event then all special identifiers (such as $nick and $chan) will be available to the alias too. So if you're really worried about commas you could write a custom identifier like this:
Code:
alias isowner {
  var %chan = $iif($2,$2,$chan), %nick = $iif($1,$1,$nick)
  return $iif($nick(%chan, %nick).pnick == ~, $true, $false)
}


and call it as:
Code:
if ($isowner) ...

inside events.

Well...
What you said above wont work in $nick(#,$nick).pnick if they were +q in a network that only supports ohv, or @%+.
Second, this is off topic but i wanted to know how you make an alias that can use the extra paramaters outside of the parenthases, eg: $eaten(%food).percent
smile Other words, i LOVE mIRC, and as sOON as I can muster up $20 ill buy it.
EDIT:{
Sorry about the large quote, im too lazy to look for stuff cuz im not usually a forum-eer
Posted By: Horstl Re: Custom Operators. - 20/08/07 05:16 AM
look up /help Custom Identifiers

e.g.:
Code:
alias custom {
  if ($prop == int) { return $int($1) }
  elseif ($prop isnum) { return $round($1,$prop) }
  else { return $1 }
}

//echo -a $custom($pi).int --- $custom($pi).3 --- $custom($pi)
returning: 3 --- 3.142 --- 3.14159265358979323846

(well, it's a quite witless example whistle )

Originally Posted By: iStink
What you said above wont work in $nick(#,$nick).pnick if they were +q in a network that only supports ohv, or @%+.
...Nor will a custom operater work in this case
Posted By: Strider Re: Custom Operators. - 20/08/07 06:05 AM
Originally Posted By: RusselB
I thought I'd seen an isowner operator in the help file already, and that Khaled had mentioned that it only worked on certain types of networks, but I was unable to locate where I was getting this information from in order to confirm it.


From the full versions.txt:
Quote:
23/09/99 - mIRC v5.61
...
2.Improved support for IRCX servers:

Added property $nick().owner, isowner if comparison, and "q"
property to $nick(#,N,aohvrq,aohvrq) where "q" is for owners.
...
Posted By: RusselB Re: Custom Operators. - 20/08/07 06:44 AM
I didn't think I was going crazy...just didn't check the right location...tried looking on the forums and in the help files for versions 6.2, 6.21 and 6.3
Posted By: Mpdreamz Re: Custom Operators. - 20/08/07 07:46 PM
Originally Posted By: starbucks_mafia
Even if custom operators were possible they would still need a prefix to distinguish them from ordinary text, otherwise you could end up with horrible problems like:
if (hello moo [color:red]newoperator %blah) ...[/color]
becoming
if (hello [color:red]moo newoperator %blah) ...[/color]
if a new script introduced a moo operator.

So with that in mind, is:
$iif($nick [color:red]$~isowner $chan)[/color]
(assuming $~ as the operator prefix) really much cleaner than
$iif($isowner($nick, $chan))


Perhaps a more subtile method is possible:

//if (hello=hello2) echo -a $v1 and $v2
is the same as if (string)

//if (hello =hello2 hello) echo -a $v1 and $v2
is the same as if (hello = hello) which is valid but deprecated
so hello2 is basicly cut off. However mIRC could in this case try to evaluate what its cutting off smile

same with
//if ($nick =opper $chan) echo -a $v1 and $v2
//if ($nick ==opper $chan) echo -a $v1 and $v2
//if ($nick !=opper $chan) echo -a $v1 and $v2


this opens up the possibility to call alias opper with $1 and $2 and perhaps a new alias $negate returning true when negated.
the called alias just returns $true or $false.

isopper is a bad example because if ($isopper) is much more cleaner in my opinion but i guess theres situations where the above can come in really handy.
Posted By: iStink Re: Custom Operators. - 22/08/07 11:09 AM
this is getting out of hand.
First off, (lol)
I had only used isowner as an example.
there could be stuff like isquadratic, or isregexmatch, ishex, isbin(ary) ishelpful isword, isblank isdone isopen isactive isheld isnick iswmword iswmwordcs so its endless for the properties for what they can manage versus aliases when they dont have $v1 or $v2.
if you want more operators, ill suggest them smile
but isowner isnt all of what im worried about... it could also be that is $nick isactive $chan, seeing how long they have been inactive/idle on $chan.
Another question, what is the difference between $~calc and $calc ?
Posted By: Riamus2 Re: Custom Operators. - 22/08/07 11:25 AM
Personally, I don't see a reason to create additional operators when the function is already available. And just because you don't like the look of it doesn't really mean it's a good thing to add additional ways to do things. Just my opinion. I don't really care either way. I just don't see any legitimate reason for it other than the cosmetic issue you mentioned.
Posted By: RusselB Re: Custom Operators. - 23/08/07 05:43 AM
Regarding $~calc and $calc, as far as I can determine, the only differences are:
1) $~calc uses one character more
2) $~calc isn't in the help file.
Posted By: Collective Re: Custom Operators. - 23/08/07 06:35 AM
Originally Posted By: RusselB
1) $~calc uses one character more
2) $~calc isn't in the help file.

3) Doesn't trigger the Identifier Warning
4) Ignores aliases
5) Has a point I can never remember
Posted By: hixxy Re: Custom Operators. - 23/08/07 11:43 AM
4) is $. and $/, $~ has a different purpose but I can't remember either.

Edit: no it's not, I misread what you said.
Posted By: Wims Re: Custom Operators. - 23/08/07 12:04 PM
$/ can be used when you have a custom alias that already exist in mIRC, exemple :

Code:
alias time return Ga!


$time will return the current time
$/time will return Ga!

I never see $~ before, i wonder what is it's utility.
$. seems to not works in mirc 6.3, not tested in previous version.
Posted By: Mpdreamz Re: Custom Operators. - 27/08/07 09:19 PM
$/ overides mirc internal alias
[code]
alias ip return dont hack my ip!
[code]

echo -a $ip and $/ip
echo's: 77.251.101.xxx and dont hack my ip!

$. silents identifiers that return a value
this also only works for mIRC internal identifiers ie:
[code]
alias return 5
[code]
//echo -a $dot $.dot $regsub(,,,,%re) $.regsub(,,,,%re) $me $.me
returns 5 5 1 Mpdreamz
the 2nd $dot isn't silenced but the 2nd $regsub and $me are.

Funny thing to note that is if you call $.ip and you have overriden $ip with your own identifier it will return your custum identifier! So we can script a simple alias to see if a mIRC ident is overriden smile

//if ($.ip != $null) echo -a $!ip is overriden by some script

This of course only work when the ident is expected to return a value and of course there's $isalias :p

also note that $/.ip (seems) to be the exact same as $/ip


I'm baffled what $~ip is doing, Khaled if you read this could you shed some light on this ??

it seem $isalias takes into account for . and /
$isalias(......./.ip) will still return $true if aliased
$isalias(~ip) will not

calling $~someCustumIdent wont work, only $~someMircIdent does.
© mIRC Discussion Forums