mIRC Homepage
Posted By: RusselB Script not working correctly. not sure why. - 14/03/06 03:49 AM
Code:
 on @*:text:!abductme:#:{
  set %question $calc($hfind(AS,$+(*,$address),0,w) + 1)
  if %question <= $lines(questions.txt) {
    .enable #input
    set %chan $chan
    question $nick $address %question
  }
  else .mode # +v $nick
}
#input off
alias question {
  set %address $2
  .msg $1 $read(questions.txt,$3)
  set %entry $gettok($read(questions.txt,$3),-1,32)
}
on *:text:*:?:{
  if %address = $address {
    .hadd -m AS $+(%entry,.,$address) $1-
    inc %question
    while %question <= $lines(questions.txt) {
      question $nick $address %question 
      inc %question
    }
    .disable #input
    .close -m $nick
    .mode %chan +v $nick
  }
}
#input end
 


I've narrowed down the problem area to that shown in the above code.

Basically the problem is that after the bot asks the first question and gets a reply, it then asks all 3 of the remaining questions without waiting for responses.

If the problem is not in this area, I will post the full code.
Posted By: Pap Re: Script not working correctly. not sure why. - 14/03/06 07:40 AM
I'm looking at your code, not really understanding what's going on, but this striked me as odd:

Code:
    inc %question
    while %question <= $lines(questions.txt) {
      question $nick $address %question 
      inc %question
    }


Is that sequence what you intended?
that looks correct. The questions (at the moment) are on lines 1-4 of questions.txt
If there is no data stored in the hash table for the person going through the questions, then %question is actually a 0 value, so to get the first line, I increase the value of %question outside of the loop.
If there is data stored, then this also ensures that the first question put to the person corresponds with the first location in the hash table that doesn't have an entry.

Then we get the loop which calls the alias question and relays the question to the person for them to answer.

Once they've answered the question, then the information is stored in the hash table and control of the script returns to the while loop, where %question is increased, then checked against the number of lines in questions.txt

A complicated answer, but hopefully one that will explain what I think should be happening.
The last poster was right, you were looping through all remaining questions sending them one after another. in the on *:text:? event. ( bit odd you didnt see it my man that flu must have taken you down alot frown )

Anyway Try this....

Code:
on @*:text:!abductme:#:{
  set %question $calc($hfind(AS,$+(*,$address),0,w) + 1)
  if %question <= $lines(questions.txt) {
    .enable #input
    set %chan $chan
    question $nick $address %question
  }
  else .mode # +v $nick
}
#input off
alias question {
  set %address $2
  .msg $1 $read(questions.txt,$3)
  set %entry $gettok($read(questions.txt,$3),-1,32)
}
on *:text:*:?:{
  if %address = $address {
    .hadd -m AS $+(%entry,.,$address) $1-
    inc %question
    if (%question <= $lines(questions.txt)) {
      question $nick $address %question 
    }
    else {
      .disable #input
      .close -m $nick
      .mode %chan +v $nick
    }
  }
}
#input end
Thanks Dave. That works perfectly. And you can change the word flu to pneumonia frown
i new it was something more complexe, but i cant spell that and also dont know what it means. :]
if interested Click Here for Wikipedia
© mIRC Discussion Forums