mIRC Home    About    Download    Register    News    Help

Print Thread
Whats wrong with this hash table? #206666 20/11/08 11:11 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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 }
}


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: Whats wrong with this hash table? [Re: sparta] #206668 20/11/08 12:34 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
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


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Whats wrong with this hash table? [Re: Wims] #206669 20/11/08 12:37 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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?


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: Whats wrong with this hash table? [Re: sparta] #206670 20/11/08 12:53 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
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'.

Last edited by Wims; 20/11/08 12:54 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Whats wrong with this hash table? [Re: Wims] #206671 20/11/08 01:12 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: Whats wrong with this hash table? [Re: sparta] #206672 20/11/08 01:16 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
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 }

Re: Whats wrong with this hash table? [Re: DJ_Sol] #206675 20/11/08 04:43 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
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 ?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Whats wrong with this hash table? [Re: Wims] #206681 20/11/08 07:08 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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.


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: Whats wrong with this hash table? [Re: Wims] #206688 20/11/08 11:05 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
I think it is better not to put people down who are trying to learn and are asking for help.

Re: Whats wrong with this hash table? [Re: DJ_Sol] #206691 21/11/08 12:10 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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

Re: Whats wrong with this hash table? [Re: Horstl] #206692 21/11/08 12:24 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Alright fine, put em down. My apologies

Re: Whats wrong with this hash table? [Re: Horstl] #206698 21/11/08 02:50 PM
Joined: Mar 2007
Posts: 218
V
vexed2 Offline
Fjord artisan
Offline
Fjord artisan
V
Joined: Mar 2007
Posts: 218
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