mIRC Home    About    Download    Register    News    Help

Print Thread
Need a loop for changing/lowering number vars... #135906 19/11/05 03:00 AM
Joined: Oct 2005
Posts: 54
B
benjy355 Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Oct 2005
Posts: 54
mmkay, I need a script to make all variables (like the numbers on the ends) lower down, mostly because of a list script for removing something off it
I'm using hash tables
Code:
on *:dialog:cmd4options:dclick:4: {
  if ($did(cmd4options,4).seltext) {
    hload hcmd4vars hash-cmd4vars.hash
    var %i 1
    while ($hget(hcmd4vars,$+(chan.,%i)) != $did(cmd4options,4).seltext) {
      inc %i
    }
    hdel hcmd4vars $+(chan.,%i)
    var %i 1
    did -d cmd4options 4 %i
    hsave hcmd4vars hash-cmd4vars.hash
  }
}

I need a way to make all the variables in between the one the person deleted to go down 1
For example
if you delete something off the list it will come as...
(in the hash table)
chan.1
#thelounge
chan.2
#moo
chan.4
#cows
chan.5
#rock
And when the list loads them
Code:
on *:dialog:cmd4options:init:0: {
  hload hcmd4vars hash-cmd4vars.hash
  var %i 1
  while ($hget(hcmd4vars,chan. $+ %i)) {
    did -a cmd4options 4 $hget(hcmd4vars,chan. $+ %i)
    inc %i
  }
}

it'll only show #thelounge and #moo
I need it to show all those four by lowering the number label on them,
from chan.4 and chan.5 to chan.3 and chan.4

Thanks very much grin


Chat NSN
My Server: sleepystickman.ircxpro.com
Re: Need a loop for changing/lowering number vars... #135907 19/11/05 03:57 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
This seems to be for the same script as in this thread: http://forums.mirc.com/s...p;page=0#143061 except that it seems you have switched from ini files to hash tables. Is there any specific reason why you are changing to hash tables? Personally, I would continue using ini unless you are planning on having hundreds of channels/items in your list.

The code I suggesting in your other thread would work well for maintaining your channel list if you use ini files. Here is code that will allow you to load/add/delete entries for your list:

Code:
;** INIT
on *:dialog:cmd4options:init:0:{
  var %c = 1
  while (%c <= $ini(cmd4vars.ini,chans,0)) {
    did -a $dname 4 $ini(cmd4vars.ini,chans,%c)
    inc %c
  }
}

;** 'Add' Button
on *:dialog:cmd4options:sclick:7:{
  if (#?* !iswm $did($dname,6).text) return
  writeini cmd4vars.ini chans $did($dname,6,1).text $ctime
  did -a $dname 4 $did($dname,6,1).text
  did -raf $dname 6 $chr(35)
}

;** 'Remove' Button
on *:dialog:cmd4options:sclick:8:{
  if (!$did($dname,4).seltext) return
  remini cmd4vars.ini chans $did($dname,4).seltext
  did -d $dname 4 $did($dname,4,1).sel
}


I used the following table from the other thread for the above code:
Code:
  list 4, 4 20 50 100, tab 1
  text "New Channel:", 5, 4 115 35 10, tab 1
  edit "#", 6, 39 114 50 9, tab 1 autohs
  button "Add", 7, 91 114 20 9, tab 1
  button "Remove", 8, 56 20 25 9, tab 1


-genius_at_work

Re: Need a loop for changing/lowering number vars. #135908 19/11/05 07:58 AM
Joined: Oct 2005
Posts: 54
B
benjy355 Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Oct 2005
Posts: 54
That may be close but now I'm doing hash tables and removing.
Thanks! grin


Chat NSN
My Server: sleepystickman.ircxpro.com
Re: Need a loop for changing/lowering number vars. #135909 19/11/05 06:38 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Here is the equivalent code for hash tables:

Code:
;** INIT dialog
on *:dialog:cmd4options:init:0:{
  if (!$hget(cmd4options)) hmake cmd4options 5
  if ($exists(cmd4options.htb)) hload cmd4options cmd4options.htb

  var %c = 1
  while (%c <= $hfind(cmd4options,chan.*,0,w)) {
    did -a $dname 4 $gettok($hfind(cmd4options,chan.*,%c,w),2,46)
    inc %c
  }
}

;** 'Add' Button
on *:dialog:cmd4options:sclick:7:{
  if (#?* !iswm $did($dname,6).text) return
  if ($hget(cmd4options,$+(chan.,$did($dname,6,1)))) return
  hadd cmd4options $+(chan.,$did($dname,6,1).text) $ctime
  did -a $dname 4 $did($dname,6,1).text
  did -raf $dname 6 $chr(35)
}

;** 'Remove' Button
on *:dialog:cmd4options:sclick:8:{
  if (!$did($dname,4).seltext) return
  hdel cmd4options $+(chan.,$did($dname,4).seltext)
  did -d $dname 4 $did($dname,4,1).sel
}

;** CLOSE dialog
on *:dialog:cmd4options:close:0:{
  hsave cmd4options cmd4options.htb
  hfree cmd4options
}


You may want to add the 'sort' switch to the list box. Hash tables don't store data in any specific order, so the list will appear in a different order each time.

-genius_at_work