mIRC Arrays v2

By ProIcons on Jan 10, 2011

Well in the previous version i had done it with variables and i have done before 3-4 years i don't remember. Anyway here is my new version with hash tables. First off all there is a feature that allows you to save the arrays. you can enable it by typing

/save_arrays <0,1>

Now
to retrive a data from an array you will type

$<arrayname>(1st index,any...)

you can now set multi-dimensional arrays by typing

/array <arrayname> a <"indexes"> <"value">
//$array(<arrayname>,a,<"indexes">,<"value">)

example

/array something a "1 4" lolen
//$array(somethingelse,a,"nikolas yo",lolen2)

you can also delete an array by typing

/array <arrayname> d
//$array(<arrayname>,d)

and you can check if an array exists

$array(<arrayname>)

Well if it has bugs or something let me know because i've made it 1:30 at midnight so .. i guess good night lol :P

Notes: Save Function not tested! :P

[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]

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 }
}
on *:start:{ 
  build_array_table
}
alias -l build_array_table { 
  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) ) {
      hload $hget(arrays,$hfind(arrays,*,%i,w)) $shortfn($mircdirarrays/ $+ $hget(arrays,$hfind(arrays,*,%i,w)))
      inc %i
    }
  }
}
alias -l 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 -l _array {
  build_array_table
  if (!$hget($hget(arrays,$1))) { 
    var %temp = $rand(A,Z) $+ $rand(a,z) $+ $rand(10,99)
    hadd -m arrays $1 %temp
    hmake %temp 100
    alias $1 $chr(123) var $+($chr(37),tempi) = $hget(arrays,$1) $chr(124) if ($2) $chr(123) var $+($chr(37),i) = 1 $chr(124) while (%i <= $!numtok($1-,32) ) $chr(123) var $+($chr(37),z) = $+($chr(37),z) $!gettok($1-,%i,32) $chr(124) inc $+($chr(37),i) $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)
  }
  else { var %temp = $hget(arrays,$1) }
  if ($2) {
    if ($2 == set) {
      hadd -m %temp $3 $4
    }
    if ($2 == del) { 
      hfree %temp
      alias $1
      hfree arrays $1
      .remove $shortfn($mircdirarrays\ $+ %temp)
    }
  }
  save_array_table
}
alias array {
  if (!$2) && ($hget(arrays,$1)) { return $1 }
  else {
    if ($2 == a) {
      var %3 = $chk($3-,1)
      var %4 = $chk($3-,2)
      var %p = $_array($1,set,$replace(%3,$chr(32),$chr(46)),$replace(%4,$chr(32),$chr(46)))
    }
    if ($2 == d) {
      var %p = $_array($1,del)
    }
    if ($2 == v) {
      return $ [ $+ [ $1 ] ] [ $+ [ ( ] ] [ $+ [ $3 ] ] [ $+ [ ) ] ]
    }
  }
}
;Obviously i don't know regex
alias chk {
  unset %result*
  unset %pending*
  var %i = 1
  var %x = 1
  while (%i <= $numtok($1-,32) ) {
    var %p = 1
    var %34 = 0
    while (%p <= $len($gettok($1-,%i,32)) ) {
      if ($chr(34) isin $mid($gettok($1-,%i,32),%p,1)) { inc %34 }
      inc %p
    }
    if (%34 > 0) {
      if (%34 == 2) { var %result $+ %x $noqt($gettok($1-,%i,32)) | inc %x }
      elseif (%34 == 1) {
        if (%pending) {
          set %result $+ %x $noqt(%pending $gettok($1-,%i,32))
          unset %pending
          inc %x
        }
        else {
          set %pending $gettok($1-,%i,32) 
        }
      }
    }
    else { set %result $+ %x $gettok($1-,%i,32) | inc %x }
    inc %i
  }
  return %result [ $+ [ $2 ] ]
}

Comments

Sign in to comment.
ProIcons   -  Jan 11, 2011

it is justa small approach to the arrays, Then i guess i must write to the description that if the array has a name of an alias it will overwrite it. But... if it is a multi line alias it will not.. this is a bug i've noticed before 5 minutes... it can't delete or replace a multiline array so the script will halt... by the way a new version released check it

 Respond  
sunslayer   -  Jan 11, 2011

using $ seems unsafe as it's possible that you could overwrite existing aliases

 Respond  
ProIcons   -  Jan 10, 2011

the chk it justs checks 2 values

//echo -a $chk(test "lol",1) = test
//echo -a $chk(test "lol",2) = lol
//echo -a $chk(test "lol omg",1) = test
//echo -a $chk(test "lol omg",2) = omg
//echo -a $chk("what if?" lol,1) = what if?
//echo -a $chk("what if?" lol,2) = lol
//echo -a $chk("what if?" "lol omg",1) = what if?
//echo -a $chk("what if?" "lol omg",2) = lol omg

Actually i've made it to take values from quotes... example if you want to set a multi dimensional array you will type

//array example a "1 1" "value" = example[1][1] = value
//array example a "3 lol" test = example[3][lol] = test
//array exampla a 5 "test omg" = example[5] = test omg

 Respond  
ProIcons   -  Jan 10, 2011

i also dont understand how your supposed to retrieve data as if you had an array "example" then according to your description you are to use $example(index); I'm not seeing how you accomplish that

hadd -m arrays $1 %temp
    hmake %temp 100
    alias $1 $chr(123) var $+($chr(37),tempi) = $hget(arrays,$1) $chr(124) if ($2) $chr(123) var $+($chr(37),i) = 1 $chr(124) while (%i <= $!numtok($1-,32) ) $chr(123) var $+($chr(37),z) = $+($chr(37),z) $!gettok($1-,%i,32) $chr(124) inc $+($chr(37),i) $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)

in $save_array if $1 == 1 you dont set anything

Fixed

 Respond  
sunslayer   -  Jan 10, 2011

I'm confused about your syntax on how to create an array

in $save_array if $1 == 1 you dont set anything

i also dont understand how your supposed to retrieve data as if you had an array "example" then according to your description you are to use $example(index); I'm not seeing how you accomplish that

for your $chk if i understood what you were trying to do you can use

/(\w+) a (?(?=\x22)\x22(.+)\x22|(\w+)) (.+)/

where \1 = array, \2 = index, \3 = values
i don't understand what a represents so i left it as a constant

 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.