mIRC Homepage
Posted By: sparta Whats wrong with this hash table? - 20/11/08 11:11 AM
I can add channels to the table, i can also remove channels from the table, but it won't halt if the #channel don't exist in the table, it says:

-> Channel "#channel" removed successfully.

but it cant have been removed successfully since it wasn't in the table, how to get around this? and can the code be made smaller? I didn't add the dialogs since they only add the value to the %var i use, and then trigger the script when i press the button.
Code:
on *:start: {
  if (!$hget(prot.channels)) { .hmake -s prot.channels 1000 }
  if ($exists(scripts\hash\channels.hsh)) { hload prot.channels scripts\hash\channels.hsh }
}

alias add-prot-chan {
  if (%add.prot.chan == $null) { echo -a -> You need to enter a channel to add first. | return }
  var %add_prot_chan = $replace($strip(%add.prot.chan),$chr(44),$chr(32)), %a = 1, %b = $numtok(%add_prot_chan,32)
  while %a <= %b {
    var %add.prot.chan = $gettok(%add_prot_chan,%a,32)
    if $hget(prot.channels,%add.prot.chan) {
      echo -a -> The channel $qt(%add.prot.chan) already exists in the list.
    }
    else {
      .hadd -m prot.channels %add.prot.chan
      echo -a -> The channel $qt(%add.prot.chan) added successfully
    }
    inc %a
  }
}

alias rem-prot-chan {
  if (%rem.prot.chan == $null) { echo -a -> You need to enter a word to remove. | return }
  if (%rem.prot.chan == No channels) { echo -a -> That text can't be removed. | return }
  if (!$hget(prot.channels,%rem.prot.chan).item) { echo -a -> The channel $+($chr(34),%rem.prot.chan,$chr(34)) does not exist in the list. }
  if ($hget(prot.channels,%rem.prot.chan).item) { hdel prot.channels %rem.prot.chan | echo -a -> channel $+($chr(34),%rem.prot.chan,$chr(34)) removed successfully. | loadprotchannels }
}
Posted By: Wims Re: Whats wrong with this hash table? - 20/11/08 12:34 PM
Because you're not using hash table correctly, it's not the first time... why can't you just read the help file and debug your code yourself ?

If you do /hadd table item1 data1, $hget(table,item1) return data1, $hget(table,item1).item return the number of item in the table (as stated in a recent thread about hash table), $hget(table,1).item will return item1 if item1 is the last added item in the table
Posted By: sparta Re: Whats wrong with this hash table? - 20/11/08 12:37 PM
This is my second table, and i didn't know what was wrong with it, and i have been reading the help file about it for more then one time, and i couldn't figure out the problem, that's why i asked here. so in other words i need to loop true the item's in the table, then grab the $hget(table,1).item <- number for the item that way?
Posted By: Wims Re: Whats wrong with this hash table? - 20/11/08 12:53 PM
This thread should already answer all of your question, you're only adding item, no data (.hadd -m prot.channels %add.prot.chan)
So $hget(prot.channels,%add.prot.chan) will return $null because it return the data value for this item, the item exists but there's no data.
Use a loop on $hget(prot.channels,N) will work but is completely useless, either use $hfind, like it was suggested in the thread or put a data, like '1'.
Posted By: sparta Re: Whats wrong with this hash table? - 20/11/08 01:12 PM
Thnx for your help, i think i solved the problem now. It's hard when you don't understand how it's done, but i think i do understand now..
Posted By: DJ_Sol Re: Whats wrong with this hash table? - 20/11/08 01:16 PM
1st of all, Wims be nice. Noone asked you to help people, ya know? If you do choose to help people you don't know you shouldn't berate them.

Sparta, this is what I do.

/hadd prot joinflood #channel1

I created an alias that will add a channel to the list if it isnt there, or remove it if it is. The end result could look something like....

$hget(prot,joinflood) == #channel1.#channel2.#channel3

So now in my event I can check:

if ($chan !isin $hget(prot,joinflood)) { return }
Posted By: Wims Re: Whats wrong with this hash table? - 20/11/08 04:43 PM
I'm nice :), it look like I'm not because his problem was already answered in the link I gave.Do you think it's better to give him the solution each time ?
Posted By: sparta Re: Whats wrong with this hash table? - 20/11/08 07:08 PM
Wims

I found the solution on here, I didn't understand how it worked, but i think i do now (thnx to your explanation about it needed to be $hget(table,item1) return data1, i missed that information in the other tread), and i can retrieve the information i need now. And i didn't use something that was "handed" to me, didn't use a single line/word that DJ_Sol pasted.
Posted By: DJ_Sol Re: Whats wrong with this hash table? - 20/11/08 11:05 PM
I think it is better not to put people down who are trying to learn and are asking for help.
Posted By: Horstl Re: Whats wrong with this hash table? - 21/11/08 12:10 AM
Imho no one was "put down" here. But learn scripting is simply 50% learn to debug a code (in this case, some echoes would have cleared up the problem) - and sparta is "carpal tunnel" in these boards by now. Honestly if it wasn't me who initially misused the .item property in the thread linked by Wims, I might have replied in a related way to fellow sparta smile
Posted By: DJ_Sol Re: Whats wrong with this hash table? - 21/11/08 12:24 AM
Alright fine, put em down. My apologies
Posted By: vexed2 Re: Whats wrong with this hash table? - 21/11/08 02:50 PM
Totally with you.

I've seen some outrageous threads on here from someone with 2600+ posts
I'm telling you, if his script gets released it'll say script v1 - by all at mirc.com grin
© mIRC Discussion Forums