mIRC Homepage
Posted By: Desolator $hfind bug/error - 27/12/11 04:50 PM
figured i would post here first to see if anyone can help before i list it as a possible bug.

if (!$hget(optotal)) { hmake optotal 5 }
; if optotal table doesnt exist, make
set -u30 %oftotco1 1
set -u30 %oftotco2 $hfind(opts,*!*@*.*.*,0,w)
;prep loop parameters, second being the total wild entries in opts
while (%oftotco1 <= %oftotco2) {
set -u5 %opmsks $hfind(opts,*!*@*.*.*,%oftotco1,w)
echo -s %oftotco1 <= %oftotco2 && opts $opretnick(%opmsks) --- %opmsks ^^ $gettok($gettok(%opmsks,2 ,64),1, 46) ~~ %opmsks
; set %opmsks as entry (needed for retrieving nickname to add up the timestamps)
;echo the loop progess and table look up command, the match returned and the nickname returned from %opmsks
if ($hget(optotal,$opretnick(%opmsks))) {
//hadd opts $opretnick(%opmsks) $+ temp $hget(optotal,$opretnick(%opmsks))
//hdel optotal $opretnick(%opmsks)
; if optotal table nickname exists, set it as new value temp and delete the saved one
//hadd opts $opretnick(%opmsks) $+ min $calc( $gettok($hget(opts,$opretnick(%opmsks) $+ temp),2,58) + $gettok($otcalc3(%opmsks),2,58) )
; retrieve the mins saved from previous session then add mins from this session to it.
if ($hget(opts,$opretnick(%opmsks) $+ min) <= 59) {
//hadd opts $opretnick(%opmsks) $+ hrs $calc( $gettok($hget(opts,$opretnick(%opmsks) $+ temp),1,58) + $gettok($otcalc3(%opmsks),1,58) ) $+ :
if ($len($hget(opts,$opretnick(%opmsks) $+ min)) == 1) { //hadd optotal $opretnick(%opmsks) $hget(opts,$opretnick(%opmsks) $+ hrs) $+ 0 $+ $hget(opts,$opretnick(%opmsks) $+ min) }
; if the new value is 59 or less (mins) add the hours of saved sessions and this session together. if the mins lengh is 1 meaning 1 min to 9 mins, add 0 infront so it returns 0X minutes.
; else the mins returned as XX and no 0 is required so just add to optotal table
else { //hadd optotal $opretnick(%opmsks) $hget(opts,$opretnick(%opmsks) $+ hrs) $+ $hget(opts,$opretnick(%opmsks) $+ min) }
}
else {
//hadd opts $opretnick(%opmsks) $+ min $calc( $hget(opts,$opretnick(%opmsks) $+ min) - 60 )
//hadd opts $opretnick(%opmsks) $+ hrs $calc( 1 + $gettok($hget(opts,$opretnick(%opmsks) $+ temp),1,58) + $gettok($otcalc3(%opmsks),1,58) ) $+ :
//hadd optotal $opretnick(%opmsks) $hget(opts,$opretnick(%opmsks) $+ hrs) $+ $hget(opts,$opretnick(%opmsks) $+ min)
; else the minutes combined were 60 or more (meaning more than 1 hour) we need to remove 60mins, add 1 to the hours to compensate then add the left over mins from subtraction to the saved mins to form the new mins total.
}
//hdel opts $opretnick(%opmsks) $+ hrs
//hdel opts $opretnick(%opmsks) $+ min
//hdel opts $opretnick(%opmsks) $+ temp
; delete all hash stuff relating to the working out times.
}
if (!$hget(optotal,$opretnick(%opmsks))) { //hadd optotal $opretnick(%opmsks) $otcalc3(%opmsks) }
if ($hget(opts, %opmsks)) { //hdel opts %opmsks }
//hsave optotal optotal.hsh
inc -u30 %oftotco1
; if it didnt exist, just add the entry from alias otcalc3 - if opts entry still exists, delete to start new, save the table for precaution inc loop vari to start again
}



alias -l opretnick { return $gettok($gettok($1, 2,64),1,46) }
alias -l otcalc3 { return $duration($calc( $gmt - $hget(opts,$1)),3) }

output now showed as:
1 <= 8 && opts nick1 --- *!*@nick1.vhost.come ^^ nick1 ~~ *!*@nick1.vhost.com
2 <= 8 && opts nick2 --- *!*@nick2.vhost.com ^^ nick2 ~~ *!*@nick2.vhost.com
3 <= 8 && opts nick3 --- *!*@nick3.vhost.com ^^ nick3 ~~ *!*@nick3.vhost.com
4 <= 8 && opts nick4 --- *!*@nick4.vhost.com ^^ nick4 ~~ *!*@nick4.vhost.com
5 <= 8 && opts --- ^^ ~~
6 <= 8 && opts --- ^^ ~~
7 <= 8 && opts --- ^^ ~~
8 <= 8 && opts --- ^^ ~~

After editing some suggestions made by argv0 - it still failed on the hfind, ive added comments into it so coders can read what its meant to be doing.
Posted By: argv0 Re: $hfind bug/error - 27/12/11 08:31 PM
Given the general complexity of the lines in your script, and the sheer number of them, I'm going to make two general assumptions:

1) The problem is most likely your script. Judging by the complexity alone, it's very likely that you just did something wrong somewhere. It's *extremely* hard for even an experienced scripter to understand what is going on there, it looks like gibberish-- which would make it completely unsurprising for it to be a bug in your script, not a bug in mIRC.

2) Your script is way too long given what you expect it to do. At first glance I see if (<value> <= 59) followed by if (<value> >= 60).. these two lines alone should be turned into an if / else pair, not two separate if (condition)s. Using else avoids the repetition of using the <value> twice, and simplifies the script, potentially reducing another point of error. You also use the same $hfind() function about 15 times in the same script... not only is this wildly inefficient, it's also once again extremely error prone. If you get a value, set it to a variable. It seems you actually did this for %oftotco2, but you don't do the same thing for $hfind(opts,*!*@*.*.*,%oftotco1,w). That would make your script much more readable and less error prone.

My suggestion would be to rewrite this from scratch in a READABLE fashion. If you can't understand what you're doing, it's more than likely that when something breaks, it's because you did something wrong and just don't know. I'm going with user error here, not a bug.
Posted By: Desolator Re: $hfind bug/error - 27/12/11 10:49 PM
Ty for the suggestions argv0, done some as uve said but it still didnt help, ive added comments as well so you understand what its attempting to do. thanks for ur time
--
Btw the purpose of this is when the person disconnects, it takes stored timestamps from the opts hash table and then figures out how long they were opping for, take the value and add it to the old saved value. This coding was used in another alias but works only if connected, the editing to this one is so it takes all stored active timestamps, and ends them to start fresh when it reconnects.
Posted By: Desolator Re: $hfind bug/error - 28/12/11 08:36 PM
i managed to fix it smile
© mIRC Discussion Forums