mIRC Home    About    Download    Register    News    Help

Print Thread
Problem with a script #229107 21/01/11 07:35 AM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
on *:TEXT:i like*:#mychannel:{
if (%flood) { return }
set -u5 %flood On
if ((myreallifename isin $1-) || ($me isin $1-)) msg $chan (message1) $nick $+ .
elseif $read(text.txt) isin $1-) msg $chan (message2) $nick $+ .
else msg $chan $1- also laugh }

This is what i have, and it works as i intended... but not always. For example: someone says "i like stuff" it will skip the first if and elseif statement as normal and do the else statement. If someone says "i like ($me)" it will do the if statement as normal. But if someone says "i like (word thats in file text.txt)" sometimes the elseif statement will activate, but the majority of the time it just goes straight to the else statement. I've been messing with this script for several hours trying to figure out why it's not working 100% of the time like i want, and i can't figure it out. Theres no other scripts running so they aren't conflicting.






Re: Problem with a script [Re: ohaithar] #229108 21/01/11 07:51 AM
Joined: Jan 2003
Posts: 64
M
MegaZeroX Offline
Babel fish
Offline
Babel fish
M
Joined: Jan 2003
Posts: 64
mm.. I'm looking at the elseif. What is the ELSEIF statement supposed to do? To me, it says you're reading a line from text.txt and then checking that line against $1-.

Re: Problem with a script [Re: MegaZeroX] #229109 21/01/11 07:55 AM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
right and if that word or phrase is in $1- then it says (message2) but it only works 5% of the time it seems. Im guesstimating when i say 5%.

Re: Problem with a script [Re: ohaithar] #229111 21/01/11 08:15 AM
Joined: Jan 2003
Posts: 64
M
MegaZeroX Offline
Babel fish
Offline
Babel fish
M
Joined: Jan 2003
Posts: 64
Your current code will only check one line from the file against $1-... is that what you want?

Re: Problem with a script [Re: ohaithar] #229112 21/01/11 08:21 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
$read(text.txt) returns a RANDOM line from the text file.
If the text file contains single words, then you want: $read(text.txt,w,$$3) ($3 is the word after "i like" and $$ means $3 must be present)
If you want to match everything after "i like" then you probably want $read(text.txt,w,$+(*,$1-,*)) or $read(text.txt,w,$+(*,$$3-,*)) depending on if you have included "i like" in your txt file or not.

See /help $read for clarification.

Re: Problem with a script [Re: 5618] #229113 21/01/11 08:39 AM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
Ok i changed $read(text.txt) to $read(text.txt,w,$$3) and it works without fail but now it wont work if someone says the word in a plural form. For example: someone says "i like dogs" and the word "dog" is in my text.txt file, it doesnt work but if they say "i like dog" it works. How can i fix that?

Edit: basically i need it so that if the text.txt word is anywhere in the "i like" sentence i need the elseif line to display (message2).

Last edited by ohaithar; 21/01/11 08:49 AM.
Re: Problem with a script [Re: ohaithar] #229114 21/01/11 10:54 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
For that kind of matching and $read, a loop over all lines of the file is inevitable.
Code:
  [...]
  else {

    ; loop all lines of the file
    var %n = 1
    while ($read(text.txt,n,%n) != $null) {
      ; check for current line matching the third word
      if ($v1 isin $3) {
        ; output and stop further processing in case of success 
        msg $chan message for line $v1 matching word $3
        return
      }
      inc %n
    }

    ; no success
    msg $chan message for no match
  }


Hash tables would allow you to search for both: any <data> matched by <wildtext> (like $read and w), and any <wilddata> matching <text> (what you're after).
Especially if you have a file with a lot of lines, the method outlined below should perform much better:
Code:
  [...]
  else {

    ; create hash table if it does not exist
    if (!$hget(likefile)) { likefile.load }
    ; check for any hash table data wildmatching the third word (returns first match only)
    if ($hfind(likefile,$3,1,W).data) { msg $chan data $hget(likefile,$v1) matches text $3 }
    ; no match
    else { msg $chan message for no match }
  }

  [...]
}

; load file into a hash table
; hash table items will be a numerical index ("line number"), the content of each line the data for that item
alias likefile.load {
  if ($hget(likefile)) { hfree likefile }
  hmake likefile
  hload -n likefile "text.txt" 
}
Note that your text file now has to contain a list of words with wildcards like *dog* or cat*
As you're not checking the file but the hash table, use the /likefile.load command after any modification of the textfile.

Last edited by Horstl; 21/01/11 11:07 AM.
Re: Problem with a script [Re: ohaithar] #229115 21/01/11 11:14 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
In addition to what Horstl gave, if all you are having trouble with are plurals, just add the plurals to your file unless that is a problem for whatever reason.

Hash tables are definitely going to be faster, though. And a regex search can also help considerably by ignoring punctuation and such.


Invision Support
#Invision on irc.irchighway.net
Re: Problem with a script [Re: Horstl] #229170 22/01/11 11:20 PM
Joined: Jan 2011
Posts: 34
O
ohaithar Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
Alright thank you guys, i think i have it working exactly how i want it to but just one last thing. I also want the script to be triggered by the words "i love" along with "i like" how would i incorporate that in the script?

Last edited by ohaithar; 22/01/11 11:27 PM.
Re: Problem with a script [Re: ohaithar] #229171 23/01/11 12:09 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Possibilities include
Code:
; check text parameters without matchtext restriction
on *:text:*:#chan: {
  if (($1-2 == i love) || ($1-2 == i like)) && ($3 != $null) { 
    [...]
  }
}

; limit matchtext and check second text parameter
on *:text:i l* *:#chan: {
  if ($istok(love.like,$2,46)) { 
    [...]
  }
}


; a regular expression for either case as matchtext
on $*:text:/^i (love|like) ./i:#chan: { 
  [...]
}

Re: Problem with a script [Re: Horstl] #229172 23/01/11 12:37 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
/^i l(ove|ike) ./i
I think only one letter l is needed.

Re: Problem with a script [Re: Tomao] #229174 23/01/11 02:45 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
*gives Tomao a cookie byte grin

Re: Problem with a script [Re: Horstl] #229190 24/01/11 03:57 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Horstl, thanks for the cookie, and I take a bite byte of your scrumptious cookie. eek