mIRC Arrays v3

By ProIcons on Jan 11, 2011

Well i guess this is the last version of mIRC Arrays...
in this version i've made the mIRC Arrays more realistic
you are able to create an array with the command

new
like in C/C++ and you are also able to delete it... with command
del
also i added a feature $afind to can search into an array
[size=13]$afind(name/N, text, N, M)[/size]
Searches array table for the Nth item name which matches text. Returns item name.
Properties: data

If you specify the .data property, searches for a matching data value.

M is optional, and can be:
n normal text comparison (default if M isn't specified)
w text is wildcard text
W array table item/data is wildcard text
r text is regular expression
R array table item/data is regular expression

Example

alias test.alias {
  new test[10][3]
  test [0] temp
  test [1] $nick
  test [2] %var
  var %i = 1
  while (%i <= $afind(test,*,0,w) ) {
    echo -a $afind(test,*,%i,w).data
    inc %i
  }
}

you can also retrive a value with
$(indexes...)

Example

alias test.alias {
  new test[10][3]
  test [0] temp
  test [1] $nick
  test [2] %var
  var %i = 1
  while (%i <= $afind(test,*,0,w) ) {
    echo -a $test($afind(test,*,%i,w))
    inc %i
  }
}

Note: The array will exist to every alias if you want to make it local just comment here with your request.. :)

[size=20]WARNING: if there is allreay an alias with the name of the array you want to create the ARRAY will overwrite the alias [/size]

on *:start:{ 
  build_array_table
}
alias save_arrays {
  if ($1 == 1) { set %arrays.save 1 | build_Array_table | echo $color(info) * Arrays Save: On }
  elseif ($1 == 0) { set %arrays.save 0 | echo $color(info) * Arrays Save: Off }
  else { echo $color(info) * /save_arrays: insufficient parameters }
}
alias -l build_array_table { 
  alias AOB return echo $color(info) * $!1 $!+ : array index out of bounds (line $!scriptline $!+ $chr(44) $!nopath($script) $!+ )
  if (!$hget(arrays)) { hmake -s arrays 100 }
  if (%arrays.save == 1) { if (!$exists(arrays)) { mkdir arrays | write $shortfn($mircdirarrays\arrays) $chr(32) | save_array_table | load_array_table } | else { load_array_table } }
}
alias -l load_array_table { 
  if (%arrays.save == 1) {
    hload arrays $shortfn($mircdirarrays/arrays)
    var %i = 1
    while (%i <= $hfind(arrays,*,0,w) ) {
      if (!$hget($hget(arrays,$hfind(arrays,*,%i,w)))) { hmake $hget(arrays,$hfind(arrays,*,%i,w)) 100 }
      hload $hget(arrays,$hfind(arrays,*,%i,w)) $shortfn($mircdirarrays/ $+ $hget(arrays,$hfind(arrays,*,%i,w)))
      inc %i
    }
    var %i = 1
    while (%i <= $hfind(arrays,*,0,w) ) {
      var %size = $hget($hget(arrays,$hfind(arrays,*,%i,w)),$hget(arrays,$hfind(arrays,*,%i,w)))
      hfree $hget(arrays,$hfind(arrays,*,%i,w))
      hmake $hget(arrays,$hfind(arrays,*,%i,w)) %size
      hload $hget(arrays,$hfind(arrays,*,%i,w)) $shortfn($mircdirarrays/ $+ $hget(arrays,$hfind(arrays,*,%i,w)))
      inc %i
    }
  }
}
alias save_array_table {
  if (%arrays.save == 1) {
    hsave arrays $shortfn($mircdirarrays/arrays)
    var %i = 1
    while (%i <= $hfind(arrays,*,0,w) ) {
      hsave $hget(arrays,$hfind(arrays,*,%i,w)) $shortfn($mircdirarrays/ $+ $hget(arrays,$hfind(arrays,*,%i,w)))
      inc %i
    }
  }
}
alias new {
  build_array_table
  var %k = 1
  var %input = $1-
  while (%k <= $numtok(%input,44) ) {
    tokenize 32 $gettok(%input,%k,44)
    var %i = 1
    var %x = 1
    while (%i <= $numtok($1-,91) ) {
      if (%i == 1) { var %arn = $remove($gettok($1-,%i,91),]) }
      else {
        var %ari $+ %x $remove($gettok($1-,%i,91),])
        inc %x
      }
      inc %i
    }
    var %i = 1
    var %p = 1
    while (%i <= $calc(%x - 1)) {
      var %p = $calc( $iif(%p,$v1,1) * %ari [ $+ [ %i ] ] )
      var %l = %l %ari [ $+ [ %i ] ]
      inc %i
    }
    if (!$hget($hget(arrays,%arn))) { 
      var %temp = $rand(A,Z) $+ $rand(a,z) $+ $rand(10,99) $+ $rand(A,Z) $+ $rand(a,z) $+ $rand(10,99) $+ $rand(A,Z) $+ $rand(a,z) $+ $rand(10,99)
      hadd -m arrays %arn %temp
      hmake %temp %p
      hadd -m %temp %temp %l
      var %1 = %arn $chr(123) var $+($chr(37),arn) = %arn $chr(124) unset $+($chr(37),ari*) $chr(124) var $+($chr(37),tempi) = $hget(arrays,%arn) $chr(124) var $+($chr(37),i) = 1 , $+($chr(37),x) = 1 , $+($chr(37),p) $chr(124) if ($isid) $chr(123) if ($2) $chr(123) while (%i <= $!numtok($1,32) ) $chr(123) var $+($chr(37),z) = $+($chr(37),z) $!gettok($1,%i,32) $chr(124) inc $+($chr(37),i)
      var %2 = $chr(125) $chr(124) return $!hget(%tempi,$replace(%z,$chr(32),$chr(46))) $chr(125) $chr(124) else $chr(123) return $!hget(%tempi,$1) $chr(125) $chr(125) $chr(124) elseif (*[*]* iswm $!1) $chr(123) while (%i <= $!numtok($1,91) ) $chr(123) set $+($chr(37),ari) $chr(91) $!+ $chr(91) $+($chr(37),x) $chr(93) $chr(93) $!remove($gettok($1,%i,91),]) 
      var %3 = $chr(124) inc $+($chr(37),x) $chr(124) inc $+($chr(37),i) $chr(125) $chr(124) var $+($chr(37),i) = 1 $chr(124) while (%i <= $!calc(%x - 1) ) $chr(123) var $+($chr(37),p) = $+($chr(37),p) $+($chr(37),ari) $chr(91) $!+ $chr(91) $+($chr(37),i) $chr(93) $chr(93) $chr(124) var $+($chr(37),l) = $!calc($iif(%l,$v1,1) * $+($chr(37),ari) $chr(91) $!+ $chr(91) $+($chr(37),i) $chr(93) $chr(93) ) $chr(124) inc $+($chr(37),i) $chr(125) $chr(124)
      var %4 = if ($calc(%x - 1) <= $!numtok($hget(%tempi,%tempi),32)) $chr(123) if (%l <= $!hget(%tempi).size) $chr(123) var $+($chr(37),i) = 1 $chr(124) while (%i <= $!numtok(%l,32) ) $chr(123) if ($gettok(%l,%i,32) <= $!gettok($hget(%tempi,%tempi),%i,32)) $chr(123) hadd -m $+($chr(37),tempi) $!replace(%p,$chr(32),$chr(46)) $!2 $chr(125) $chr(124) else $chr(123) $!AOB(%arn)
      var %5 = $chr(125) $chr(124) inc $+($chr(37),i) $chr(125) $chr(125) $chr(124) else $chr(123) $!AOB(%arn) $chr(125) $chr(125) $chr(124) else $chr(123) $!AOB(%arn) $chr(125) $chr(125) $chr(124) save_array_table $chr(125)
      alias %1 %2 %3 %4 %5
      save_array_table
    }
    else { echo $color(info) * new: array allready exists }
    inc %k
  }
}
alias del {
  if ($hget(arrays,$gettok($1,1,91))) {
    var %temp = $hget(arrays,$gettok($1,1,91))
    hfree %temp
    alias $gettok($1,1,91)
    hdel arrays $gettok($1,1,91)
    .remove $shortfn($mircdirarrays\ $+ %temp)
    save_array_table
  }
}
alias afind {
  if ($isid) {
    if ($hget(arrays,$1)) {
      if ($prop == data) {
        return $hget($hget(arrays,$1),$hfind($hget(arrays,$1),$2,$3,$4))
      }
      else {
        return $hfind($hget(arrays,$1),$2,$3,$4)
      }
    }
  }
}

Comments

Sign in to comment.
sunslayer   -  Jan 17, 2011

hmm, i didn't know about those types of comments.

 Respond  
mSLChampagne   -  Jan 17, 2011

It's all in context though; you are right Jethro_. When used as an operator it utilizes an isMultiple() function of sorts ... when used in conjunction with a command it forces evaluation i.e. //noop $ident(a) $ident(b). But when used with nothing, simply // as it were, then there is no command to evaluate anything for. Same as Jaytea was saying with the empty command bit.

 Respond  
Jethro   -  Jan 17, 2011

I thought the // was both an operator and evaluator> // v2 is a multiple of v1also the double forward slashes tell mIRC to evaluate identifiers compared to the single one which prints the identifiers themselves.

 Respond  
jaytea   -  Jan 17, 2011

sunslayer, see http://www.mirc.com/faq7.html under 'The ; and REM flag'

it's treated as a comment if mIRC recognizes /REM as the command before any code is evaluated, so you can even use //REM to mimic C style single line comments. you can even use this:

alias myalias {
  echo -a line1

  // this is a comment

  echo -a line2
}

mIRC sees this as an empty command and ignores it without evaluating the rest of the line.

 Respond  
mSLChampagne   -  Jan 16, 2011

Well, that is definitely an opinion as it is a legitimate method of commenting but in consideration of keeping to stricter standards I will add them for you.

 Respond  
sunslayer   -  Jan 16, 2011

interesting approach mSLChampagne, but your comments are quite annoying and should be prefixed with a ;

 Respond  
mSLChampagne   -  Jan 16, 2011

Here, this differs from the last one I pasted in that I simplified it. It also has an example at the end of it to better show it's usage.

It does require that you have .NET 2.0 at least I believe, which is really standard to have these days. Unless you're using linux. :> If that's the case then COM will only work (and terribly I might add) through the use of WINE or some other similar emulation.

alias -l inherits if (!$com($1)) halt
alias -l object { if (!$com($2)) .comopen $2 $1 
  return $iif($com($2).progid == $1,$2,$null)
}

alias array { 

  ; REM ## Object initialization ##
  inherits $object(system.collections.arraylist,$1)

  ; REM ## Method handling ##
  if ($2 == sort    ) noop $com($1,sort,1)
  if ($2 == clear   ) noop $com($1,clear,1)
  if ($2 == append  ) noop $com($1,add,1,string,$3)
  if ($2 == remove  ) noop $com($1,remove,1,int,$3)
  if ($2 == insert  ) noop $com($1,insert,1,int,$3,string,$4)
  if ($2 == removeat) noop $com($1,removeat,1,int,$3)
  if ($2 == reverse ) noop $com($1,reverse,1)
  if ($2 == delete  ) .comclose $1

  ; REM ## Property handling ##
  if ($2 == item  ) return $null($com($1,item,3,int,$3)) $com($1).result
  if ($2 == count ) return $null($com($1,count,3)) $com($1).result
  if ($2 == exists) return $null($com($1,contains,3,string,$3)) $com($1).result

}

alias test { 

  var %a = example, %b = 10

  ; REM ## Create an array by the name of "example."
  noop $array(%a)

  ; REM ## Populate the array with some data.
  while (%b) {
    noop $array(%a,append,%b)
    dec %b
  }

  ; REM ## Reverse the array.
  noop $array(%a,reverse)
  linesep

  ; REM ## Enumerate and echo each item in the array.
  %b = 0
  while ($array(%a,item,%b)) { 
    echo -a Item %b $+ : $v1
    inc %b
  }
  linesep

  ; REM ## Determining the size and whether an item (data) exists or not.
  echo -a Count: $array(%a,count)
  linesep
  noop $array(%a,append,z)
  echo -a Exists("z"): $array(%a,exists,z)
  linesep

  ; REM ## Bit sorting the array is the built-in default method shown here.
  noop $array(%a,sort)
  %b = 0
  while ($array(%a,item,%b)) {
    echo -a Item %b $+ : $v1
    inc %b
  }
  linesep

  ; REM ## Clearing and deleting an array.
  noop $array(%a,clear)
  noop $array(%a,delete)

  ; REM ## End of test.
  echo -a End of test.
  linesep

}
 Respond  
ProIcons   -  Jan 16, 2011

My Brothers wrong, re post your code if you want. and if you do i want you to explain me something..

 Respond  
sunslayer   -  Jan 16, 2011

No Problem at all this is an open source code site, that someone can actually fix someones else code and suggest him or show him his code

 Respond  
mSLChampagne   -  Jan 16, 2011

There's really no need to be snippy about it. We all know it's your thread and we all know you've pasted three variations. We are just showing you other methods to increase your knowledge by allowing you to see other methods in action. That way you can take it upon yourself to further your own instruction. Obviously, with the reaction you gave, you haven't much desire to take it upon yourself to learn anything past the norm. Since it is such a problem for me to do the same as sunslayer has for you I will remove mine.

 Respond  
ProIcons   -  Jan 16, 2011

Well it is nice way. but this is my post, if you forget it. Post is somewhere else, i am not a newbie i know the ways but i decided to post this. -.-

 Respond  
mSLChampagne   -  Jan 15, 2011

.

 Respond  
ProIcons   -  Jan 14, 2011

@sunslayer and what is the point to execute a regex without result? [i don't know anything about regexes..]
@Jethro_ yeap it executes an alias, or a function without returning a value... but like i asked sunslayer what's the point to execute a regex without returning a value...? the regml? :/

 Respond  
IllogicTC   -  Jan 14, 2011

@ProIcons: I was making jest of the fact that usually someone will eventually wander by this and complain that you took up another 2 milliseconds of processing time using an alias to call an $hget(). Though I'm fairly certain that for a single or a few instances, the total amount of extra processing time would be imperceptible to humans.

 Respond  
Jethro   -  Jan 13, 2011

Prolcons, the command /noop can apply to other uses as well, not just regex. Here are two examples I hereby demonstrate:

//noop $$?"Enter Anything:" | echo -a $!
//noop $tip('Tray Tip', $me says: $+ ,test!,5)

The first one acts like a popup dialog where you enter anything to have it echoed. The seconds is a balloon tip, where it pops up on your right hand corner of your PC task bar. Again, there are other scenarios /noop can be used in conjunction with other identifiers...

In older mirc versions, /noop functions the same as that of /echo -q

ProIcons  -  Jun 22, 2013

Well i understood after some years lolmao.

Sign in to comment

sunslayer   -  Jan 13, 2011

its used when you don't want to return any extraneous data, i.e.
if you use /echo $regex(aa,/(.)/g) it would echo a 2 in your window which is generally not want you want so you use noop $regex(aa,/(.)/g) to stop it from returning a value.

its similar to
var %variable = $regex(aa,/(.)/g) so you could perform a regex match without having to echo anything

 Respond  
ProIcons   -  Jan 13, 2011

Jethro_ like i said, i never need it, i never saw it before ... i am developing alone i never ripped a code, so for all my scripts this command never needed. And i would want to learn what it exactly does, but atm i want more to learn Regular Expressions :D

 Respond  
Jethro   -  Jan 13, 2011

Prolcons, you have no clue as to how the /noop command works, don't you?

 Respond  
ProIcons   -  Jan 13, 2011

and what's the point of that? a command that it does nothing?

 Respond  
sunslayer   -  Jan 13, 2011

@Prolcons, the noop command stands for "no operation" in that it does nothing

/noop $regex(blah...) will evaluate $regex but will do nothing else, whereas /echo $regex(blah...) would evaluate $regex and then echo the result

 Respond  
ProIcons   -  Jan 13, 2011

@sunslayer No Problem at all this is an open source code site, that someone can actually fix someones else code and suggest him or show him his code, Anyway, it seems good [i don't test it] ehm but i have a question. All the years i am scripting, in mIRC scripting i didn't use never the command "noop" can you explain me what it exactly does with regexes... because the mIRC help file doesn't help me to understand it... napa182 told me that executes the identifier i guess.
[13/01/2011@00:58:26] //noop $$?="enter whatever" | echo -a $!
[13/01/2011@00:58:37] it treats it like a norm command
but still i didn't understand how it works with regexes anyway. I told you that this Version of mIRC Arrays it has this type of identifiers. The v2 allows you retrive data with alias $array and you can comment the line "alias $2" to avoid creation of an alias with the name of the array.

@lllogicTC i actually didn't understand the first sentence :P, and yeah it is interesting this idea for the users that knows other languages with arrays.

 Respond  
IllogicTC   -  Jan 13, 2011

<-- Waiting for some dolt to butt in and go "But you could just call an $hget() yourself instead of calling an ident that calls an $hget(), after 1000 iterations it cost me 10 WHOLE EXTRA TICKS!"

I actually find this idea quite interesting, it gives a different view on how to store data without just directly using a method directly programmed into mIRC itself. Also, it has a feel similar to other languages, and could help people looking into mSL as a new language to learn to warm up to it quicker.

 Respond  
sunslayer   -  Jan 11, 2011

not meaning to hi-jack your post but here's my method of using arrays, supports multi-dimensional arrays, and multi-type keys(int or string)

alias array {
  /*
  * Start of data parsing
  * Do not edit
  */
  .noop $regex(prop,$prop,/^(\w+)(\x28(.+)?\x29)?/)
  var %this = $+(ARRAY.,$$1),%prop = $iif($regml(prop,1),$regml(prop,1),init),%param = $iif($regml(prop,3),$v1,$null),%addData = .hadd %this
  if (%param) { .tokenize 44 %param }
  if (!$hget(%this) && %prop != init) { echo -a * Error: Object not initialized | halt }
  if ($isalias($+(%this,.,%prop,.PRIVATE))) { echo -a * ERROR: Unable to access Method $qt(%prop) | halt }
  if ($regml(prop,0) == 1) { $iif($1,.hadd %this %prop $1,return $hget(%this,$prop)) | halt }
  $iif($isalias($+(%this,.,%prop)),noop $+($,%this,.,%prop,$chr(40),%prop,$chr(44),$1-,$chr(41)),.goto %prop)
  halt  | ; prevent script from passing this point

  /*
  * Class methods
  * Start editing here
  */
  :init
  if ($hget(%this)) {
    echo -a * Error: Array already exists
    halt
  }
  .hmake %this 10
  return 1

  :add
  if (!$3) {
    echo -a * ERROR: insufficient parameters
    halt
  }
  var %index = $replace($($+($,2-,$calc($0 -1)),2),$chr(32),$chr(243)),%data = $($+($,$0),2)
  .hadd %this %index %data
  return 1

  :get
  if (!$2) {
    echo -a * ERROR: insufficient parameters
    halt
  }
  var %index = $replace($($+($,2-,$0),2),$chr(32),$chr(243))
  echo -a $iif($hget(%this,%index),$v1,$null)
  return 1

  :destroy
  if ($hget(%this) && $2 == 1) { .hfree %this }
  return 1

  :error
  echo -a $iif($error,$v1,Unknown error) in Class: $qt(%this)
  .reseterror
  return 0
}

syntax:
$array() ; creates the array
$array(,index,data).set() ; sets data
$array(,index).get() ; retrieves data

examples:
$array(test)
$array(test,1,this is stored in index 1).set()
$array(test,2,1,this is stored in index 2[1]).set()
$array(test,1).get() returns "this is stored in index 1"
$array(test,2,1).get() returns "this is stored in index 2[1]"
$array(test,4).get() returns $null

 Respond  
ProIcons   -  Jan 11, 2011

Jethro_ probably it will not :D what else can i do ?:P

 Respond  
napa182   -  Jan 11, 2011

LMFAO @ Jethro_

 Respond  
Jethro   -  Jan 11, 2011

So when's v4 gonna be due out? :P

 Respond  
napa182   -  Jan 11, 2011

so you are saying it's an updated version of what you had LMFAO hence update ur old version.

 Respond  
ProIcons   -  Jan 11, 2011

it is different to add arrays and delete arrays, also to find arrays... the only same thing is the way it queries the arrays... and not exactly the same but anyway...

 Respond  
sunslayer   -  Jan 11, 2011

it still holds the same concept, ive updated my OOP snippet 3 times, all with diverse changes, this still does not give reason to post a new snippet

 Respond  
ProIcons   -  Jan 11, 2011

in the previous version if you noticed you could comment, the alias line and it has
$array(arrayname,v,indexes)
but here i've made it this way to look like more than the C/C++ arrays, they could use the version 2 and comment the line alias, is the same thing without alias...

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.