mIRC Home    About    Download    Register    News    Help

Print Thread
I need some help on $read and $readini #213181 21/06/09 07:55 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
Hello everyone.I will try to explain my question clealry. now I have use writeini written a ini.but when I try to output the contains of ini file I got a problem.

writeini -n file.ini %string1 %string2 %string3

now the ini stored like this
Code:
 
[%string1]
%string2=%string3

%string1,%string2 and %string3 r not exactly the same everytime.
now I want to match if another var called %string4 isin %string2
and msg out to a channel as " %string4 %string1 %string3 ".But I can't use $readini(file.ini, %string1, %string2) to match since what I require to match is in ITEM but not VALUE.

and for $read I use

Code:
  
 if ( %string4 isin $read(file.ini) ) { 
    msg #channel  something
    HALT
 }


this does work sometimes. because it reads random line.So it doesn't work all the time.Is there any possible way to read the full contains of a text file,and return the string I searched for? Anyway I has tried
Code:
$read(file.ini, w, *string*)
 

but it return only the first line it found. is there any possible way to return all the line it found? also in read seems we can't use variables such as $read(file.ini, w, *%string1*)
and I noticed there is a "r" for $read for regex match. how to use it? can anyone of u gimme a example?
Thanks for your reading.

Re: I need some help on $read and $readini [Re: feisu] #213183 21/06/09 08:20 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
You may want to try replacing spaces with underscores in your stored lines of text.

eg
[section]
This_is_what_i'm_looking_for=This is the answer
Here_is_another=This is another result

this means you can use a $readini method and is a lot faster then then searching through using the $read method

hope this helps

Re: I need some help on $read and $readini [Re: NoZparker] #213184 21/06/09 08:30 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11

At first,thanks for ur reply
there isn't any spaces stored in my ini file. I already replace it with $chr(46) which means .

Now my problem is that I can't match the string in item. I want if sometext I require match in item then msg out the line.
here is my ini file
[Scripted]
Gossip.Girl=USA

I'm scripting a tvshow script. I want if the showname exist in my ini then halt.if not keep connecting to web and check,after return written down in ini in this format.

now the problem is the match. I already made if someone type !tv "Gossip.girl" or "gossip girl" set gossip = %string2 in regex.

I want if gossip isin Gossip.Girl then msg something out "Gossip.Girl USA Scripted" directly,or "Gossip.Girl=USA Scripted". But seems this is impossible in this way. U know the string1,2 and 3 r not the same everytime.

Re: I need some help on $read and $readini [Re: feisu] #213185 21/06/09 08:40 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
i've never had too much luck with the wildcard search
how i get around it is :-
var %line 1
While ($read(file.txt,%line) != Null){
if (%searchtxt isin $read(file.txt,%line)) {
msg $chan $gettok($read(file.txt,%line),2,61)
break or halt
}
inc %line
}


not the best method but it does work (providing the file.txt is not too big

Last edited by NoZparker; 21/06/09 08:42 AM.
Re: I need some help on $read and $readini [Re: NoZparker] #213186 21/06/09 08:45 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
that's what I want:D but how many time will it loop? what if I need to match 2 string at same time? is it the same? for is there any way to count how many line does a text file have and then loop the times. I will try it later.
BTW,msg $chan $gettok($read(file.txt,%line),2,61)
what does this line do .the 2,61 I'm new in script.Sorry for stupd question:) and gettok.

I've tried it but mirc returns
/while: insufficient parameters (line 65, script2.mrc)

line 65 is
While ($read(E:\feisu\mIRC\feisu.ini,%line) != Null){
I've tried renamed ini into txt but still no luck

Last edited by feisu; 21/06/09 08:52 AM.
Re: I need some help on $read and $readini [Re: feisu] #213187 21/06/09 08:55 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
;start search line
var %line 1

; stops when it reaches the end of the file
While ($read(file.txt,%line) != Null){

;compares the search with what is read
if (%searchtxt isin $read(file.txt,%line)) {

;or search for two strings
if (%searchtxt1 isin $read(file.txt,%line)) || (%searchtxt2 isin $read(file.txt,%line)) {

;msg the channel with the result
msg $chan $gettok($read(file.txt,%line),2,61)

;stop the search or comment out this line if you want multiple results
break or halt
}

;echo the line number that a result was found in
echo -a found in line %line

;increment the line that is to be read
inc %line
}


try that

Re: I need some help on $read and $readini [Re: NoZparker] #213188 21/06/09 09:14 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
Code:
 
on *:text:*:#channel: { 
  var %line 1
  While ( $read(E:\feisu\mIRC\feisu.ini, %line) != Null) {
    if (gossip isin $read(E:\feisu\mIRC\feisu.ini,%line)) {
      if (gossip isin $read(E:\feisu\mIRC\feisu.ini,%line)) || (girl isin $read(E:\feisu\mIRC\feisu.ini,%line)) {
        msg $chan $gettok($read(E:\feisu\mIRC\feisu.ini,%line),2,61)
        break or halt
      }
      echo -a found in line %line
      inc %line
    }
  }
}

It is what I wrote to test.
I was just want to test if search function works. but It caused my mirc looping.nonresponse.so I have to use taskmgr close it;P. in feisu.ini I have Gossip.Girl=USA as contain.so I promise there is a gossip and girl in it.
Thanks for ur help again:)

Re: I need some help on $read and $readini [Re: feisu] #213189 21/06/09 09:18 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
on *:text:*:#channel: {
var %line 1
While ( $read(E:\feisu\mIRC\feisu.ini, %line) != Null) {
if (gossip isin $read(E:\feisu\mIRC\feisu.ini,%line)) || (girl isin $read(E:\feisu\mIRC\feisu.ini,%line)) {
msg $chan $gettok($read(E:\feisu\mIRC\feisu.ini,%line),2,61)
halt
}
echo -a found in line %line
inc %line
}
}

Last edited by NoZparker; 21/06/09 09:19 AM.
Re: I need some help on $read and $readini [Re: NoZparker] #213190 21/06/09 09:25 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
seems now it workins preferly:) can I have one more require. makes it stop after 5secs if still nothing found in text.because if there isn't anything match in file. it still keep looping makes my mirc crash:) and. it echo the wrong line for found.
echo -a found in line %line
if mirc found it in line 3 but line 1 or 2 do not have it wil lecho

found in line 1
found in line 2

Last edited by feisu; 21/06/09 09:29 AM.
Re: I need some help on $read and $readini [Re: NoZparker] #213191 21/06/09 09:28 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
now the above snippet will trigger on every line of text that is sid in the channel
to trigger only queries use
on *:text:~*:#channel: {

the script will only ten trigger when ~gossip or ~girl is typed in the channel

to search for other stuff
use

on *:text:~*:#channel: {
var %search1 $replace($gettok($1-,1,32),~,$null)
var %search2 $gettok($1-,2,32)

this make %search1 = Gossip
and %search2 = girl
when ~gossip girl is typed in the channel

Re: I need some help on $read and $readini [Re: NoZparker] #213192 21/06/09 09:30 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
it will only pass through the file once
my last post (up there) should remidy your crashing

Re: I need some help on $read and $readini [Re: NoZparker] #213193 21/06/09 09:33 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
yeah I knew that.for setting var by that is a good way:) and also for prefix. but still no fix if it doesn't found anything in text it will keep loop.maybe we halt for the wrong result?

Re: I need some help on $read and $readini [Re: NoZparker] #213194 21/06/09 09:36 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
this line :-

While ( $read(E:\feisu\mIRC\feisu.ini, %line) != Null) {

means that it will search through the file until it reaches the end (just once)

if it finds a match it is halted by the halt command anyway


how many lines are in the file ?

Re: I need some help on $read and $readini [Re: NoZparker] #213195 21/06/09 09:44 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
Code:
on *:text:~*:#channel: {
  var %search1 $replace($gettok($1-,1,32),~,$null)
  var %search2 $gettok($1-,2,32)
  var %line 1
  While ( $read(E:\feisu\mIRC\feisu.ini, %line) != Null) {
    if (%search1 isin $read(E:\feisu\mIRC\feisu.ini,%line)) || (%search2 isin $read(E:\feisu\mIRC\feisu.ini,%line)) {
      msg $chan $gettok($read(E:\feisu\mIRC\feisu.ini,%line),2,61)
      halt
    }
    echo -a found in line %line
    inc %line
  }
} 
 


this is my mrc.and here is ini below
Code:
 
Gosdsip.Gdirl=USA
girl=bbs


whne I have ablow ini and type ~gossip girl in other mirc. this mirc returns

Code:
[xx:xx] <@nick1> ~gossip girl
found in line 1
[xx:xx] <@nick2> bbs
 


but when my ini become
Code:
Gosdsip.Gdirl=USA 


the mirc crash .with only 1 line:P

Last edited by feisu; 21/06/09 09:45 AM.
Re: I need some help on $read and $readini [Re: feisu] #213196 21/06/09 09:48 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
shouldn't that be

Gossip.Girl=USA

rather then

Gosdsip.Gdirl=USA

after all your looking for gossip not gosdsip

also i think one of the probs is you need at least 2 lines of text in the file

Last edited by NoZparker; 21/06/09 09:53 AM.
Re: I need some help on $read and $readini [Re: NoZparker] #213197 21/06/09 09:57 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
seems there is some misunderstanding between us:)

that line is for if script doesn't found what should it do.

I wish script stop this loop. if it doens't find.clearly the script doesn't stop when it should. ok.
with
Gossip.Girl=USA
Prison.Break=USA
it works and return USA but when I remove Gossip.Girl=USA from ini and left Prison.Break=USA only it crashed.this is the problem. but echo say found in line 2:)
I want script stop the loop after searched done and keep doing what it should do in next line of this. seems now script have something need to be fixed but we haven't found yet for stop the loop. if it haven't found the string I want.

now I have 6 Prison.Break=USA in ini but still crashs:) u can try ur self.anyway thanks for helping.I'm really appreciate it

Last edited by feisu; 21/06/09 09:59 AM.
Re: I need some help on $read and $readini [Re: NoZparker] #213199 21/06/09 10:02 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
there are many conditions you can add to your script to make it more efficient
eg
if (%search2 != $null)
and
if ($count($1-,$chr(32)) == 0) {
var %search1 $replace($1-,~,$null)
unset %search2
}
if ($count($1-,$chr(32)) == 2) {
var %search1 $replace($gettok($1-,1,32),~,$null)
var %search2 $gettok($1-,2,32)
}

Re: I need some help on $read and $readini [Re: NoZparker] #213200 21/06/09 10:11 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
I will try it later. now I still think that we loop While in the wrong way.since echo returns found in line 1 found in line 2 found in lin 3 found in line 4 found in line 5 when the string which matchs is in line 6 when it exists.. so I think the position of halt might be wrong.

Re: I need some help on $read and $readini [Re: NoZparker] #213201 21/06/09 10:14 AM
Joined: Jan 2006
Posts: 34
N
NoZparker Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Jan 2006
Posts: 34
silly mistake ... $ missing from null

on *:text:~*:#channel: {
var %search1 $replace($gettok($1-,1,32),~,$null)
var %search2 $gettok($1-,2,32)
var %line 1
;the $ was missing from this next line
While ( $read(E:\feisu\mIRC\feisu.ini,%line) != $null) {
if (%search1 isin $read(E:\feisu\mIRC\feisu.ini,%line)) || (%search2 isin $read(E:\feisu\mIRC\feisu.ini,%line)) {
msg $chan $gettok($read(E:\feisu\mIRC\feisu.ini,%line),2,61)
;comment out the halt for multiple results
halt
}
inc %line
}
if ($read(E:\feisu\mIRC\feisu.ini,%line) == $null) {
msg $chan Cant find any results
}
}

Last edited by NoZparker; 21/06/09 10:21 AM.
Re: I need some help on $read and $readini [Re: NoZparker] #213202 21/06/09 10:22 AM
Joined: Jun 2009
Posts: 11
F
feisu Offline OP
Pikka bird
OP Offline
Pikka bird
F
Joined: Jun 2009
Posts: 11
Wow.Now it works like a charm. laugh I'm newbie.So I didn't notice it neither.

I'm really thanks for ur time today:) Have a good day.