mIRC Homepage

What am I doing wrong?

Posted By: The_Game

What am I doing wrong? - 24/06/04 01:31 AM

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.
Posted By: Coolkill

Re: What am I doing wrong? - 24/06/04 01:51 AM

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.
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 12:38 PM

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
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 02:07 PM

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
Posted By: tsoglanos

Re: What am I doing wrong? - 24/06/04 04:02 PM

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,...
Posted By: tidy_trax

Re: What am I doing wrong? - 24/06/04 04:06 PM

Just to do it how the game wanted it: write -s $+ $did(4).text test.txt $did(4).text
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 06:04 PM

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
Posted By: tsoglanos

Re: What am I doing wrong? - 24/06/04 07:23 PM

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...
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 07:29 PM

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.


Posted By: tsoglanos

Re: What am I doing wrong? - 24/06/04 07:31 PM

he, the are no spaces in nicknames =) try yourself and post again.
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 07:33 PM

I do not recall myself saying that nicknames consist of spaces.

Seriously, read carefully before writing.
Posted By: tsoglanos

Re: What am I doing wrong? - 24/06/04 07:40 PM

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.
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 08:09 PM

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)
Posted By: tsoglanos

Re: What am I doing wrong? - 24/06/04 08:37 PM

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
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 08:45 PM

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!

Posted By: tsoglanos

Re: What am I doing wrong? - 24/06/04 08:53 PM

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....
Posted By: The_Game

Re: What am I doing wrong? - 24/06/04 09:05 PM

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.
Posted By: FiberOPtics

Re: What am I doing wrong? - 24/06/04 09:07 PM

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.

Posted By: The_Game

Re: What am I doing wrong? - 25/06/04 04:46 AM

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.
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 11:26 AM

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 } }
Posted By: FiberOPtics

Re: What am I doing wrong? - 25/06/04 11:41 AM

Hi,

there are many ways to create a pm blocker. Personally I would go with a Hash Table, or perhaps the User List.
However, it's your script so I'll give you a solution that is closest to the way you like it.

Now, your test.txt file consists of lines with on each line 1 nickname, no spaces.

An altered $isinfile alias using $read instead of filter works great for your script, since it's single words, not multiple words on each line. The filter solution is preferable in the case of multiple words on one line.

Example code:
Code:
 
alias isinfile {
  if !$isfile($$1) { echo -a Error: File $1 missing. | return }
  if $2 == $null { echo -a Error: Matchtext missing. | return }
  .echo -q $read($1,s,$2)
  return $readn
}
[color:red]  [/color] 
on ^*:OPEN:?:*:{
  if !$isinfile(test.txt,$nick) { echo -a  $+ $nick just tried messaging you : 12 $+ $1- | halt }
}

Hope it is to your likings,

Greets

Edit: added the ^ in front of the event thanks to tsoglanos.
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 11:58 AM

hi Fiberoptics =)

first you forgot to add on text the (^) so the halt or haltdef can work
second i it halts all querys even from users/nicks are in test.txt listed.

Dont`t call me baby,..

Posted By: FiberOPtics

Re: What am I doing wrong? - 25/06/04 12:13 PM

Hi tsoglanos,

you have not carefully read my script.

1. You are right, i forgot to add it. When you need to use ^ with halt or not isn't really well defined in mIRC. For example in the ON INPUT you don't need it to halt something. Good remark.

2. Right now it only halts the script if a user is not in the script. Because i put if !$isinfile(...

Note the negating !, that means only people who are not in the file will be halted. The halt is within the braces { } that follow the !$isinfile, which means that the halt will only be triggered when the person is not in the file, which is what The_Game wants. He wants only people who are in the file to be able to pm.

3. Your script is BAD, and I'll try to explain to my best why it is. Be sure to do some tests this time before responding, ok?

-->
Ok $read(test.txt,w,$+(*,$nick,*)) will search in the text file looking for *nickname*.

If it doesn't find a match, %m will be $null and that means that person isn't in the text file, and that the pm should be blocked.

So far so good.

Now, suppose in your text file you have:

TheOne
TheBigOne
Gooney

and a person with the nick "One" wants to message. Then your script will search for *one* and it will trigger on TheOne. So %m will be filled with TheOne, and the script will not block the pm. But as you can see this is not the good result, because we want to check if that nickname "One" is in the text file. One isnt in the text file, so he should be blocked, but in your script he is allowed.

4. Well tsoglanos, it seems that you are not as experienced in scripting yet, so please really from now on, try to test the code first, try to read it, try to learn from it, and then, when your postive that somethign is mistaken, let me know. But right now, you're making a fool out of yourself :tongue:

Greets
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 12:26 PM

Well this is not a big deal it was just a typo
Ignore the * *

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


why you think if somone has a question you must make a scripting tutorial.,about my scripting expirience I have enouth so i can give a simpel and worket explain
somthing i mising in your explains =) don`t private anymore i just Ignore you and you post bye!
Posted By: FiberOPtics

Re: What am I doing wrong? - 25/06/04 12:38 PM

I'm sure putting $+(*,$nick,*) was a typo. *cough cough*


What you are missing is the ability to properly read and write in the English language.

Not only confusing me, but also confusing yourself when you're trying to interpret other people's posts.

And the reason that I have almost been giving scripting tutorials is because of this confusement. I had to wheigh my every word, because you could interpret it wrong because of your lack in English.

Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 12:40 PM

and before you post again of course you can replace w with s
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 12:44 PM

you sould realy change this: In theory, there is no difference between theory and practice. But, in practice, there is


Becuse the code you post is anithing else then what the game asked for,.., put the foul code if you now how so everone can easy test and Understend what you are posting
Posted By: FiberOPtics

Re: What am I doing wrong? - 25/06/04 12:45 PM

You cant' replace w with s in this case, because when doing $read(test.txt,s,$nick) the script will read from the text file, and scan for that word ($nick) and it will return what is following that first word on the line.

Example (here I go again giving you a scripting tutorial, because you obviously need one):

In your text file:

tsoglanos
fiberoptics this is the text that will be returned

//echo -a Result: $read(test.txt,s,tsoglanos)
--> Returns: Result:

//echo -a Result: $read(test.txt,s,fiberoptics)
--> Returns: Result: this is the text that will be returned

In other words, your %m will always be empty even if it did find a match in the text file, because in The_Game's text file it is only nicknames, with nothing following it.

Posted By: FiberOPtics

Re: What am I doing wrong? - 25/06/04 12:49 PM

Lol,

that code works perfect for what The_Game is requesting, and everybody except you is not understanding it. But I can't blame you really, your too busy confusing yourself.

Posted By: Mentality

Re: What am I doing wrong? - 25/06/04 01:55 PM

-General Reply-

I don't think it's necessary to pick at each other's code. It's not a competition. Obviously, the best code, 'cleanest' and so on is preferred but if you have a suggestion to someone who is helping about how they could improve then, in general, it would be better to PM the person. I believe FibreOptics opted to do this and tsoglanos started again.

This "check what you said before you post again" attitude is not necessary and it's rude. I think getting rude with each other is going to start an argument and is not productive to this thread! Picking at forum signatures is even less so and completely unnecessary.

Regards,
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 02:09 PM

this tsoglanos stardet again I realy dont like it if you read all post you will realise i stardet nothing i just posted somthing thes all and Fiberoptics stardet, not me and Mentality you are are moderator in this formum so you now we have in the past fight , but this has nothing to do with my post or this room also act like a moderator and keep you private fight or probleams you have with me out of this formum , we are all intrsting to Help with mIRC becuse we are all mIRCers nothing more.,..
greats.
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 02:18 PM

Ah and Mentality if you are public post you think Fiberoptics

Is the best way why you are not just test fibers code first.,

alias isinfile {
if !$isfile($$1) { echo -a Error: File $1 missing. | return }
if $2 == $null { echo -a Error: Matchtext missing. | return }
.echo -q $read($1,s,$2) return $readn
}
on ^*:OPEN:?:*:{
if !$isinfile(test.txt,$nick) { echo -a  $+ $nick just tried messaging you : 12 $+ $1- | halt } }

after you test this code post the results!
Posted By: Mentality

Re: What am I doing wrong? - 25/06/04 02:20 PM

I ensure you I am being completely objective and ensuring this does not go into an argument, and at the same time I will not participate in one with you.

If you have further questions, comments or queries about my post, please private message me. Thank you smile

Regards,
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 02:42 PM

the best way to do what the game want is a while loop with $read(test.txt,N)


on ^*:OPEN:?:*:{ var %t = 1 | while ($read(test.txt,%t)) { inc %t | if ($read(test.txt,%t) == $nick) { return } | else { echo -a  $+ $nick just tried messaging you : 12 $+ $1- | halt } } }

Posted By: tidy_trax

Re: What am I doing wrong? - 25/06/04 02:46 PM

Code:
on ^*:open:?:{ 
  if (!$read(test.txt,r,/^ $+ $nick $+ $/i)) { halt }
}


The above is the simplest way i can think of.

Edit: if you want case-sensitive nicks in the test.txt file, remove the i in /i
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 02:51 PM

he i tring the r before you postedt but this wrong

if you have in test.txt write

tso
tsoglanos
tsoglanos29
and somone with the nick tsog pm you it you will not block him smile
Posted By: tidy_trax

Re: What am I doing wrong? - 25/06/04 02:54 PM

Yes you will, the ^ and $ make sure of that:

Code:
//write -c nicks.txt tso | write nicks.txt tsoglanos | write nicks.txt tsoglanos29 | if (!$read(nicks.txt,r,/^tsog$/i)) { echo -a this will be halted }
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 03:11 PM

Well tidy sory but it your fall

you used wrong the on open

^*:open:?:{

it can only be on :OPEN:?:*:{

and second this is my test.txt

tso
tsoglanos29
tsoglanos293

this is the nick i using tsog

and this is the code
on ^*:open:?:*:{ if (!$read(test.txt,r,/^ $+ $nick $+ $/)) { halt } }

it is the same like ,w,*nick*

when i type with the nick tsog /msg XXX-0758282137692 ela re

it still open a query

I using mIRC 6.15

and now debug you script

add this echo -a $read(test.txt,r,/^ $+ $nick $+ $/))

i using the nick tsog and i get the nick tsoglanos29

you see?

I realy don`t try to make a scripting chalenger with you

I only try to help but there are always some guys the want to prove how good the are smirk why ?

Posted By: tidy_trax

Re: What am I doing wrong? - 25/06/04 03:15 PM

First of all, the on open event doesn't need *, regardless of what the help file says.
Second, w,*nick* would be ,r,.*nick.*, mine will only match the complete nickname, if you actually type the example i gave you, you will see that it says "this will be halted", and it will be halted.
Posted By: tsoglanos

Re: What am I doing wrong? - 25/06/04 03:22 PM

again debug your script

my nick is tsog

in test.txt

i have

tsoglanos
tsoglanos29

and only becuse tsog is in tsoglanos or tsoglanos29

you script dont halt

here is an expalin how to debug your script, if you are to tiredt to test the script why you are posting?

on ^*:open:?:*:{ echo -a $read(test.txt,r,/^ $+ $nick $+ $/) }
Posted By: tidy_trax

Re: What am I doing wrong? - 25/06/04 03:31 PM

It seems you are the one who isn't testing it, tsog may be in tsoglanos, but the ^ and $ means it will only match tsog, nothing else, it will not match tsoglanos and it will not match tsoglanos29, it will only match tsog, nothing else.
Posted By: Mentality

Re: What am I doing wrong? - 25/06/04 03:37 PM

I believe The_Game has been answered. This thread has turned into picking at each other's code and it isn't productive nor necessary as I have already said once.

Use the PM feature for further discussion with each other as I've also said.

Regards,
© 2022 mIRC Discussion Forums