mIRC Homepage
Posted By: Elva reading/writing and other questions. - 17/09/06 04:09 AM
Ok, Im just learning, had a bit of a look and couldnt find the info I wanted so I hope this doesnt turn out to be something thats already been covered.

couple of questions...

1. I currently have a script that has the variable %channels, and a popup to reset the value for that variable. What I want to know is how i would set it to add a channel to the list thats already there instead of resetting the whole lot. I hope I made that clear?

2. I want a remote script to write to a file, then scan that file for a line beginning with a specific word, then read that line back, then edit a part of that line leaving the rest as is, then read back the whole file.

Example:
tom says "!write m00 one" (writes: m00 one: tom - two: - three: - )
jess says "!write Arg two" (writes: Arg one: - two: jess - three: - )
jess says "!write m00 three" (edits the m00 line so that it says m00 one: tom - two: - three: jess -)
jack says "!write m00 three" (edits the m00 line so that it says m00 one: tom - two: - three: jack -)
then the trigger "!read m00" reads back the line starting with m00
and the trigger "!readall" reads the whole file.

Is that clear? is this even possible and how do i do it?

Thanks in advance for any help smile
Posted By: Scorpwanna Re: reading/writing and other questions. - 17/09/06 06:28 AM
Here's just some quick info. Nothing that's really super huge or hard, but good if you're starting out I think.

/write filename data

and

$read(filename,s,text)

Lets assume you have %channels as:
%channels #channel1,#channel2,#channel3

If so:

Usage: /addchannel #channel4
alias addchannel { set %channels %channels $+ , $+ $1 }
Which makes: %channels #channel1,#channel2,#channel3,#channel4

If channels are located in a file lets say called channels.txt and the file looks like this:

#channel1
#channel2
#channel3

/write filename #channel4

Then have it read it back like the example next.

2.
/write filename blah thar's a worm on a hook
someone types: blah
on 1:text:*:#: {
var %whatever $read(filename,s,$1)
if (%whatever) { msg $chan %whatever }
}
Posted By: Elva Re: reading/writing and other questions. - 17/09/06 07:41 AM
ok
that answers my first question nicely, thankyou smile
still not sure on the second one.
Posted By: Scorpwanna Re: reading/writing and other questions. - 17/09/06 03:39 PM
Quote:
2. I want a remote script to write to a file, then scan that file for a line beginning with a specific word, then read that line back, then edit a part of that line leaving the rest as is, then read back the whole file.


Usage: /blah then some stuff here
Code:
alias blah {
 ;I want a remote script to write to a file
  write filename $1-
  ;$1- means first/param word to last
  ;then scan that file for a line beginning with a specific word
  var %readdata = $read(filename,s,$1)
  var %readline = $readn
  if (%readdata) {
    ;then read that line back
    echo -ag Data Found on line %readline
    echo -ag Line equals: $1 %readdata
    ;then edit a part of that line leaving the rest as is
    var %replacedata = $replace(%readdata,find this,replace with this)
    ;overwrite the readn line with the new data
    write -l $+ %readline $1 %replacedata
  }
  ;then read back the whole file
  var %i = 1
  var %lines = $lines(filename)
  while (%i <= %lines) {
    echo -ag $read(filename,%i)
    inc %i
  }
}

That's probably nowhere close to what you have pictured or how you want it, but hopefully some of this information will help you. Anything is possible in mIRC, it just takes time to learn what does what. You want it to do something but don't know how yet but you'll eventually get there smile.
Posted By: RusselB Re: reading/writing and other questions. - 17/09/06 04:22 PM
Quote:
Code:
  var %i = 1
  var %lines = $lines(filename)
  while (%i <= %lines) {
    echo -ag $read(filename,%i)
    inc %i
  }  
This is fine with the echo usage, however, if they wanted the information sent to a channel or another nick, then they'd be better off using
Code:
 play <#channel/nick> filename 
, due to the fact that a large file sent to a channel or nick using the original format would probably get them flooded off of the server.
Posted By: Scorpwanna Re: reading/writing and other questions. - 17/09/06 04:50 PM
Yep.
Posted By: Elva Re: reading/writing and other questions. - 20/09/06 12:23 AM
much appreciated smile
© mIRC Discussion Forums