mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 3 1 2 3
What am I doing wrong? #87949 24/06/04 01:31 AM
Joined: Dec 2002
Posts: 1,237
T
The_Game Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 1,237
What I am trying to do is to stop adding the nickname more than once to the file by looking for the nickname and if it exists, to not write it. If it does to write it. (And no writing to files is not one of my strong points if you haven't already guessed.)

Code:
if ($did == 5) {
  if ($did(4).text isin test.txt) {
    .echo $did(4).text is already listed!
    halt
  }
  else {
    .write files\test.txt $did(4).text
  }
}


Thanks in advance.

Re: What am I doing wrong? #87950 24/06/04 01:51 AM
Joined: Dec 2002
Posts: 788
C
Coolkill Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
The "isin" statement is to check whether a partial string is inside a full string, i.e. if (a isin abc)..

To check whether a string is in a file you can use $read

for example..

if ($read(files\test.txt,w,$+(*,$did(4).text,*)) { Your Command }

Will return the first result in a search for *STRING* in a file however a better parameter than 'w' to use might be 's' depending on whether you have 1 nickname per line, if so use..

if ($read(files\test.txt,s,$did(4).text) { Your Command }

If 'w' or 's' parameter isnt to your liking you may have to loop the file looking for an exact match in which case..

var %i $lines(C:\test.txt) | var %t 0 | while (%i) { if ($read(C:\test.txt,%i) == $did(4).text) { var %t 1 } | dec %i } | if (%t == 1) { echo ALREADY EXISTS } | else { echo DOESNT EXIST }

Replacing echo ALREADY EXISTS and echo DOESNT EXIST with whatever you may.

For more information /help $read if you require it.

Hope this Helps.

Eamonn.

Re: What am I doing wrong? #87951 24/06/04 12:38 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

to know if there is an exact string in that file, I wouldn't loop through each line.

Perhaps this alias can be handy:
Code:
 
alias isinfile filter -ff test.txt nul $$1 | return $filtered 

Usage: $isinfile(nick)

I'm assuming here that test.txt is a file located in the main mIRC folder, and that each line represents 1 nick.

Greets @Coolkill and The Game


Gone.
Re: What am I doing wrong? #87952 24/06/04 02:07 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

I've added some more functionality and error checking to the isinfile alias.
Code:
  
alias isinfile {
  if !$isfile($$1) { echo -a Error: File $1 missing. | return }
  if $2 == $null { echo -a Error: Matchtext missing. | return }
  filter -ff " $+ $1" nul $2- 
  return $filtered 
}

Usage: $isinfile(file,string)

Examples:

$isinfile(test.txt,The_Game)
$isinfile(c:\program files\mirc\text files\test.txt,bleh blah)
$isinfile(test.txt,The_*me and F*OPt*)

The file can be put without a path if it is located in your main mIRC folder. It supports spaces in the path, as you can see. Thanks to the /filter you can also use wildcards in your search string. The matchtext can be multiple text now, instead of 1 word.

So "string" for exact matching, and "*string*", "*str?ng*" etc. for wildcard matching.

Hope you find this useful,

Greets


Gone.
Re: What am I doing wrong? #87953 24/06/04 04:02 PM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
It is very simpel

type it 10 times

/write -stsoglanos29 test.txt tsoglanos29

just use the -s switch

The -s switch scans a file for the line beginning with the specified text and performs the operation on that line.

Don`t call me baby,...

Last edited by tsoglanos; 24/06/04 04:10 PM.
Re: What am I doing wrong? #87954 24/06/04 04:06 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Just to do it how the game wanted it: write -s $+ $did(4).text test.txt $did(4).text


New username: hixxy
Re: What am I doing wrong? #87955 24/06/04 06:04 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Ah yes,

I assumed that "-s scans file beginning with string" meant the following:

Suppose you have a text file with:

mirc
mir
mi
m

I assumed if you did $read(test.txt,s,m) that it would return the line beginning with an "m" which would be mirc. However, mirc scans as stated for a "word" which i should literaly translate to a string followed by a space. In this case, if there is only 1 word on each line, then the $read and -s switch are the way to go.

In the case of having multiple words on 1 line, then -s is useless.

Consider:

this is a test
this is a
this is

then $read(test.txt,s,this is) is useless to check if the string "this is" is somewhere in the file as a stand alone string, because it will match on the "this is a test" line.

Anyway, the $isinfile alias is redundant in The_Game's case, though it can prove to be handy in other situations.

Greets


Gone.
Re: What am I doing wrong? #87956 24/06/04 07:23 PM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
You miss the point

The -s switch scans a file for the line beginning with the (specified text)

now make you test and see

/write -stsoglanos29 test.txt tsoglanos29

/write -stso test.txt tso

/write -stsoglanos293 test.txt tsoglanos293

and you will realise one more nick is just add and not
replaced, I holp u accept this becuse it is a fact ...

There is always one more bug...

Re: What am I doing wrong? #87957 24/06/04 07:29 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

I did not miss the point lol. Read my post again.

Quote:

Ah yes,

I assumed that "-s scans file beginning with string" meant the following:

Suppose you have a text file with:

mirc
mir
mi
m

I showed you first what I wrongfully assumed with an example.

I also said:

Quote:
In this case, if there is only 1 word on each line, then the $read and -s switch are the way to go.


Then I showed you in a second example where -s is useless.

So to summarize so everyone understands:

-s is useful if we are talking about lines starting with single words, not with multiple words. I'm very aware that nicknames do not consist of spaces, however there might be other occasions where there CAN be strings with multiple spaces, and in THOSE cases, -s is useless.




Gone.
Re: What am I doing wrong? #87958 24/06/04 07:31 PM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
he, the are no spaces in nicknames =) try yourself and post again.

Re: What am I doing wrong? #87959 24/06/04 07:33 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I do not recall myself saying that nicknames consist of spaces.

Seriously, read carefully before writing.


Gone.
Re: What am I doing wrong? #87960 24/06/04 07:40 PM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
write a nickname to a file.txt nickname if it exists, to not write it again

/write -sSomenick test.txt Somenick

is the simpel way to do this , no need to use if-then-else and filter end of discusion.

Re: What am I doing wrong? #87961 24/06/04 08:09 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

I'm very aware of that since you've posted it the first time. I've explained to you how I assumed (wrongfully) that -s works differently in case of single words.


I also tried to explain to you, that in a case where there are multiple words on a line (this example has nothing to do with what The_Game requested) that the -s is useless.


Am I getting through here? Hello?

So once again:

1. Yes, indeed, as you stated, and as I have acknowledged, the read -s switch is the right way to go in the case of The_Game's request , because he just wants to scan a string without spaces (nicknames, indeed). Note how I'm saying that the -s switch is the right way here, and it workx, and I wrongfully assumed in my very first post that it didn't work like that.

2. Now the part that doesn't seem to get through to you:
In a case where we are talking about lines in a text file which consist of multiple words (that's right, multiple words, so not nicknames, so not the example by The_Game, so a completely different situation), THEN -s is useless, as I showed you with an example.

Now, to summarize everything once again (just making sure):

In this case where the text is only nicknames, the -s thing is the RIGHT way. (<-- did you see it? Did you read it? Is it getting through?)
In other cases with multiple words, the -s thing is NOT the right way.

Well, enough of this thread for me, if I still don't get through to you, then there is nothing I can do anymore for you. I should not even have bothered to try to explain, but I couldn't help it. In the future, I'll just let things as is, and try not to worry too much about the fact that I'm being misunderstood.


Edit: After reading this whole thread again: Lol, here's where tsoglanos and me got mixed up, because he is talking about /write -s and I wrongfully thought he was talking about $read with s. And vice versa: I was talking about $read with s switch, while he wrongfully thought I was talking about the /write with s switch. Damn, text based communication can be frustrating at times :tongue: (/me grabs a beer)

Last edited by FiberOPtics; 24/06/04 09:18 PM.

Gone.
Re: What am I doing wrong? #87962 24/06/04 08:37 PM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
Mensch meir!

I realy have nothing against you but why are trying to help somone at simpel at posibel

The question is not what dose the -s switch if we have multi lines begins with the same text , but how to store nicknames to a txt Once, it would be not very smarth
to add nicknames twice and more and then trying to filter doubel text out.

First write -stsoglanos29 test.txt tsoglanos29 will never allow
add the same nick twice
also your explain about
multi lines is in this situasion not valid.

anyway even if u use multi lines and the first word is difrent
then -s is still valid

/write -stsoglanos29 test.txt tsoglanos29 this is the 1st

/write -stsoglanos293 test.txt tsoglanos293 this is the 2nd

/write -stso test.txt tso this is the 3rd

It would not be valid like you post if the first word in the line
would ecxist twice and more


/write -stsoglanos29 test.txt tsoglanos29 this is the 1th

/write -stsoglanos29 test.txt tsoglanos29 this is the 2nd

/write -stsoglanos29 test.txt tsoglanos29 this is the 3rd

But this is inposibel in my explain

sory for my bad english smile

and i realy not tring to atack you Fiberoptic, I only tring to give a quick and efective help easy to Understend even for newbies

Re: What am I doing wrong? #87963 24/06/04 08:45 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I am talking about multiple words on the same line.

Have you still not read my example:

Text file:

this is a test
this is a
this is

You see 3 lines with MULTIPLE words on each line, and the $read(test.txt,s,this is) will match on the FIRST line on the text "this is a test" which we do not want.

How many times am I going to have to tell you, that this issue has NOTHING to do with The_Game's example. Again: this has NOTHING to do with The_Game's example, I am talking about $read in a different situation than The_Game's situation, where it is a /write. Do you get the difference?

The $read is just something I said aside from this thing that The_Game is requesting. Have you not read in my previous post, that I said that it is working the right way that you proposed?

So do you understand now that I'm talking about reading from a file and that the -s switch will be useless, and that i'm NOT talking about writing with the -s switch, where it is working perfectly as you suggested.

Just to clarify, I have nothing against you, I just really get stressed when people are misunderstanding what I'm saying.


Oh well, atleast we kept it civil. Cya on some other thread!



Gone.
Re: What am I doing wrong? #87964 24/06/04 08:53 PM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
For the last time you post makes no sense how asked ? about -s don`t work if you have 10 times the same line in a txt?

first read the post the game made, and then think about your post and the -s switch....

Re: What am I doing wrong? #87965 24/06/04 09:05 PM
Joined: Dec 2002
Posts: 1,237
T
The_Game Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 1,237
By using one of the examples and doing a little reading, I did seem to find what I was looking for. By using the below example, I was able to add a nickname to this list. If the nickname was already there, it would echo something that notified you that the nickname existed and would stop. If the nickname didn't exist, it would write it. So far it seems to have worked cause its not adding the same nickname to the file more than once.

Code:
if ($did == 5) {
  if ($read(files\test.txt,w,$+(*,$did(4).text,*))) {
    .echo -a $did(4).text is already listed.
    halt
  }
  else {
    .write files\test.txt $did(4).text
    .timer 1 1 echo -a $did(4).text was added to the list.
  }
}


By the way I just wanted to say thanks for the help thus far. If there's anything else I may be overlooking feel free to point it out.

Re: What am I doing wrong? #87966 24/06/04 09:07 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
That's because you are talking about /write -s in this example of The_Game,

and because I am talking about $read with the s flag in an examle NOT of The_Game, but for a general example. An example where a script needs to check if a certain string is in a text file or not.

Well it's very clear to me now, I should have been even more specific that I was talking about $read with -s switch, whilst you were trying to convince me of /write -s, where I know that /write -s works well even with multiple words, its just that $read doesn't work well with it.

Anyway, because this thread is becoming ridiculous (I'm ashamed of it), I've pm'd you so let's keep it private.

Oh well, we got carried away, it happens, no offence intended, cya around.



Gone.
Re: What am I doing wrong? #87967 25/06/04 04:46 AM
Joined: Dec 2002
Posts: 1,237
T
The_Game Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 1,237
Ok now I need something to work with the above script I last posted. Something that works for the pm as an example.

Code:
on ^1:OPEN:?:*: {
  ; if statement that allows mIRC to open private message windows only nicknames from test.txt
  ;
  ; if user is not on this list, no window will popup at all. and will echo the following to my active window
  ; .echo -a  $+ $nick just tried messaging you $+ : 12 $+ $1-
}


If you haven't guessed, its sort of a private message blocker that im trying to make for my girlfriend. And since I know hardly a thing about read/write commands, it has been quite a pain in my ass

If you can help with this one too, I would appreciate it.

Re: What am I doing wrong? #87968 25/06/04 11:26 AM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
Actuali do the same you did before only replace $did(4).text
with $nick,...

on ^1:OPEN:?:*: { var %m = $read(test.txt,w,$+(*,$nick,*)) | if (%m == $null) { echo -at * $nick just tried messaging you $+ : 12 $+ $1- | halt } }

Page 1 of 3 1 2 3