Ok, this may take me a while so I'm going to go ahead and post this here edit the post to then describe what each line does:

on *:text:*:#: {
on "anylevel" "text" "anytext" "anychannel"

if ($1 == ?) {
if the first word is a question mark

var %text = $2- =>
create the temporary variable %text which equals the second word to the end and add to it a =>

%text = $read(learnt.txt, w, %text $+ *)
reads learnt.txt for a line beginning with %text (plus our =>) and anything after it. using a => makes sure it finds the right line info because only 1 line will be exactly what it's looking for.

;if "this entry*" is found at the beginning of a line,
if (%text) {
if %text exists/is found/is not empty but is actually something

var %term = $reptok(%text,=>,is,1,32)
create the temporary variable %term and replace the first => found with the word "is". Since we added it to make sure it searched and found exactly what we wanted, we don't need it anymore so we change it back to "is". The tokens as they are called in this example separated by the character 32 (which is a space) so every word is a token because it's separated by a space

msg $chan hmm, %term
message to the active channel hmm, %term information it found
}
}
if ($1 == !append) {
if the first word is !append

var %islocation = $findtok($2-,is,1,32)
create temporary variable %islocation to find where "is" is we use $findtok to search the "second word to the end" for the word "is" only looking for the "first" one and separate the information using character 32/a space
When found returns it's position in the text.

if (%islocation) {
if %islocation is found, not empty etc...

var %text = $2-
create temporary varilable %text from the second word until the end of the sentance

%text = $reptok(%text,is,=>,1,32)
we update the %text variable into: replace "in the text" the first "is" with "=>" separating the text by a space character 32
that way we transform the %text with is, into the %text with =>

var %newentry = $gettok(%text,1- $+ %islocation,32)
create temporary variable %newentry, get the tokens (words in this case) in %text, from first word until where %islocation/"is" was found. Returns the text entry only until where is was found. "the information =>" (remembering we replaced is with => instead of "the information => found"

var %findentry = $read(learnt.txt,w,%newentry $+ *)
create temporary variable %findentry which reads learnt.txt searching for a line beginning with the data %newentry returns
So it searches for a line beginning with "the information =>" and returns "the information => found"

var %foundentry = $gettok(%findentry,1- $+ %islocation,32)
create temporary variable %foundentry get the tokens (words in this case) from the first word until where %islocation/"is" was found. Returns the text entry only until where is was found. "the information =>".

You may be saying that this looks familiar to %newentry, only difference is, one is reading text from the text you supply, one is reading from a file.

if (%newentry == %foundentry) {
if %newentry is equal to %foundentry (if "the information =>" is equal to "the information =>" use the functions within the { }'s

var %append = $gettok(%text,$calc(%islocation +1) $+ -,32)
create temporary variable %append, get the tokens (words in this case) starting from %islocation plus 1 (making it skip showing the => in the results all the way to the end of the new information. Separated by a space/character 32. so instead of returning "=> the new info" it returns "the new info"

write -l $+ $readn learnt.txt %findentry or %append
write "on line $readn" (the line read in a text file during this operation) to the file "learnt.txt" "%findentry" (which returned "the information => found") and add to the end of it "or %append" (which returned "the new info")
the updated line written is "the information => found or the new info"

msg $chan Appended data.
messages the active channel "Appended data."

}
}
}
if ($1 == !replace) {
if the first word is !replace

var %islocation = $findtok($2-,is,1,32)
again we search for the first is location in the text starting from the second word until the end

if (%islocation) {
if %islocation is found, not empty etc...

var %text = $2-
create temporary varilable %text from the second word until the end of the sentance

%text = $reptok(%text,is,=>,1,32)
we update the %text variable into: replace "in the text" the first "is" with "=>" separating the text by a space character 32
that way we transform the %text with is, into the %text with =>. Which returns "the information => the new info"

var %newentry = $gettok(%text,1- $+ %islocation,32)
var %findentry = $read(learnt.txt,w,%newentry $+ *)
var %foundentry = $gettok(%findentry,1- $+ %islocation,32)
if (%newentry == %foundentry) {
var %replace = $gettok(%text,$calc(%islocation +1) $+ -,32)
does the same as the above does for append but!

write -l $+ $readn learnt.txt %newentry %replace
instead of appending, it overwrites the entire line with the new data, without saving the old with it.

msg $chan Replaced entry.
messages the active channel Replaced entry.

}
}
}
if ($1 == !learn) {
if the first word is !learn

var %islocation = $findtok($2-,is,1,32)
again find the location of is

if (%islocation) {
yada yada yada

var %text = $2-
create temp variable %text using the second word until the end

%text = $reptok(%text,is,=>,1,32)
var %newentry = $gettok(%text,1- $+ %islocation,32)
var %findentry = $read(learnt.txt,w,%newentry $+ *)
var %foundentry = $gettok(%findentry,1- $+ %islocation,32)
if (%newentry == %foundentry) {
same as above but! if it's found it tells you it already exists rather than doing anything about it.

msg $chan Already have something for that.
messages active channel "Already have something for that.
}
else {
if the %newentry isn't %foundentry or default to using this

write learnt.txt %text
write to a new line in learnt.txt "the information => the info"

;write this to a file: this entry => that info
;after it's done writing verify that the data did write to the file and if so have it tell you "ok".
remark lines in mirc

if ($read(learnt.txt,w,%text)) { msg $chan ok }
reads learnt.txt for a line matching "the information => the info" if it exists and matches, messages active channel ok, verifying that it learned the information

else { msg $chan I pooped my pants }
if it failed to write the information successfully it messages the active channel that it pooped it's pants smile
}
}
}
if ($1 == !delete) {
if the first word is !delete

var %text = $2- =>
create the temporary variable %text which equals the second word to the end and add to it a =>

%text = $read(learnt.txt, w, %text $+ *)
update the variable %text with the information found from reading learnt.txt for a line beginning with "the information =>"

if (%text) {
if found/exists/is not empty...

write -dl $+ $readn learnt.txt
use write to delete the line read during the $read operation, removing the entry from the learnt.txt file.

msg $chan Deleted entry.
message active channel "Deleted entry.

}
else { msg $chan Info does not exist to delete }
if not found/edists/or is empty(nothing returned) message the active channel "Info does not exists to delete"
}
}


Hope that helps you understand more about mirc smile.

Last edited by Scorpwanna; 22/09/06 07:01 PM.

We don't just write the scripts, we put them to the test! (ScriptBusters)