Author Topic: [Turtorial]How to let your bot read a file.  (Read 175 times)

King_Hual

  • Trial Moderator
  • Newbie
  • ***
  • Posts: 36
  • Reputation +3/-2
    • View Profile
Re: [Turtorial]How to let your bot read a file.
« on: February 10, 2011, 03:29:19 pm »
Hello. Today I'm REALLY gonna explain how the bot reads files. And to be more specific, how the bot reads a random line from a file. For example, the file will be C:\slap.txt. You can create it in any folder, and then just put the destination to it at the place where i put "file name", or the example file name.

Code: [Select]
on *:TEXT:!slap*:#: { It's obvious that this is the TEXT event.
 
Code: [Select]
msg # $read(C:\slap.txt, $r(1,$lines(C:\slap.txt) ) )
}
"$read(file name, line to read)" opens and reads the file (a specific line from it), and then returns the text from the line. To read the random lines like in the example above, just type $r(1, $lines(file name) ) where the "line to read" text is. "$lines(file name)" returns the total value of the lines. Like if you have 2 lines, it will return a value of 2.

And the full code:
Code: [Select]
on *:TEXT:!slap*:#: {
  msg # $read(C:\slap.txt, $r(1,$lines(C:\slap.txt) ) )
}

If you have any questions ask me, rookies  ;)
« Last Edit: February 10, 2011, 04:13:33 pm by King_Hual »