mIRC Home    About    Download    Register    News    Help

Print Thread
#188009 16/10/07 04:14 AM
Joined: Mar 2005
Posts: 2
K
KCN Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
K
Joined: Mar 2005
Posts: 2
Just a noob thought...
would be nice to be able to compare more than 2 items directly:

Code:
if (%var1 = %var2 = %var3) instead of 

if ((%var1 = %var2) && (%var2 = %var3))


It would certainly simplify things smile

KCN #188018 16/10/07 10:17 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Personally, I don't like the idea of changing the logic operations in the scripting language. I can see such changes making code become ambiguous and/or difficult to understand once you start taking that idea further into comparing a lot of things at once. There's nothing wrong with using &&, imo.


Invision Support
#Invision on irc.irchighway.net
KCN #188401 22/10/07 01:50 PM
Joined: Oct 2006
Posts: 48
G
Ameglian cow
Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 48
I already gave a similar suggestion (with loads of replies) here...


https://forums.mirc.com/ubbthreads.php?ubb=showflat&Number=186484&page=2#Post186484

KCN #188466 23/10/07 10:02 PM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Originally Posted By: KCN
Just a noob thought...
would be nice to be able to compare more than 2 items directly:

Code:
if (%var1 = %var2 = %var3) instead of 

if ((%var1 = %var2) && (%var2 = %var3))


It would certainly simplify things smile


If you absolutely need something to mimic that behaviour, you could use your own alias as a function/identifier.

Example:
Code:
allequal {
  var %f = $1 , %i = 2 , %n = $0
  while (%i <= %n) {
    if ($ [ $+ [ %i ] ] != %f) { return $false }
    inc %i
  }
  return $true
}


if ($allequal(1,1,1,1,1)) { echo -a all parameters are equal }

This method is probably the best way, albeit a little slow. The plus of it is that you can use variables in it, separated by commas. :P


Or if you really want to keep the syntax in your example (note, that if you use it this way, %var can not contain a =, or this will not work properly.)

Code:
aeq {
  if ($regex($1-,/^((.*?)(?: = \2){1,})$/)) { return $true }
  return $false
}


if ($aeq(one = one = one)) { echo -a they are all one! }



Anyway, enjoy!


Link Copied to Clipboard