mIRC Home    About    Download    Register    News    Help

Print Thread
#42415 17/08/03 02:21 PM
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
I wrote a function a long time ago (~v5.51) that I called $isswitch. It's very messy but did the job... yet, I'd like to see it built into mIRC, considering that mIRC already does this internally for every command with switch parameters.

$isflag(%string, [N/-flag], [N], [+-/])
Returns the Nth flag (aka switch) in a string if a number is specified. If N is 0, then the number of flags is returned. If a flag is specified, it returns a number of occurances of that flag in the string. The optional third parameter allows you to specify which flag you're refering to, if it appears more than once. The optional fourth parameter allows you to specify what symbols identify a flag's polarity.

Properties: val, pos, pol, flag.
val     returns the value associated with that flag, if it has one.
pos    returns the flag's relative position.
pol     returns the flag's polarity, that is, the switch character used. (+-/)
flag    returns the full flag, including its polarity character and value.


Examples:
simple_use {
  if ($isflag($1)) {
    if ($isflag($1,-x) do this
    if ($isflag($1,+y) do that
    if ($isflag($1,z) move zig
    tokenize 32 $2-
  }
do stuff $1-
}

advanced_use {
  var %i = 0, %n = $isflag($1,0)
  WHILE (%i < %n) {
    inc %i
    echo -a Flag %i : $isflag($1,%i).flag
    if ( $isflag($1,%i).pol == + ) mode $chan - $+ $isflag($1,%i)
} }

Better Examples:
$isflag(-ti2m) == 3             (total flags)
$isflag(-ti2m,0) == 3          (total flags)
$isflag(-ti2m,-i) == 1          (total occurances)
$isflag(-ti2m,i).val == 2       (value of flag)
$isflag(-ti2m,i,1).val == 2     (value of 1st i flag)
$isflag(-ti2m,2) == i            (Nth flag)
$isflag(-ti2m,i).pos == 2      (position of flag, not counting polarity character or values)
$isflag(-ti2m,i).pol == -       (polarity of this flag)
$isflag(-ti2m,i).flag == -i2    (the complete flag, including polarity and value)

$isflag(+a-b/c2@d&f5*g, 3, @*-+&/) == c   (you get the idea)

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#42416 17/08/03 05:13 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
That would make flags about 1000x more complicated than they are currently with no real bonus. Just do what everyone else does and use if (-* iswm $1) followed by $count() and/or $regex to get flags. Since most flags aren't immediately followed by their value then an identifier like this would have very limited abilities anyway.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#42417 17/08/03 05:20 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
mIRC probably does have something like this internal, however I doubt it is standardized like you suggest.
Some identifiers for example use
/ident -f[N]

some use
/ident -f [param]

some use
/ident -f +F [param]

Each identifier does things differently. Like I'm thinking of the -l flag to /window. That is -l[N]. Whereas, /log has -f [filename]. I think it would be nearly impossible for mIRC to standardize this so that it could be a simple $isflag identifier.

#42418 17/08/03 10:39 PM
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
It would be entirely possible for mIRC to standardize this, as it's up to the user to actually test which parameters contain flags, and which do not.

I fully appreciate how /window -flags +flags, and even /server -a server -g group, and other commands differ from any formal standard... but this doesn't stop $isflag from doing its thing.

As to starbucks post, most mirc command switches DO contain the number value within the switch set, NOT as a seperate parameter. Regardless though, it's up to the user to decide how they want to handle their flags. If they detect -i flag, then they should anticipate $2 as being a number param, and /tokenize 32 $3- accordingly.

Command switches are highly standardized in one very loose, yet consistant, standard... as I thought I had demonstrated in the features I had given to $isflag.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!

Link Copied to Clipboard