Viewing topic:PHP irc bot
Page:
1
04-11-2007 - 15:47
hey, i was trying to make my bot take a random line from a file and print it in the irc chan, i have tried and tried and am rather stumped on how to do it, any help wil be apreciated.
04-11-2007 - 17:24
Hey 
Thats a nice question, i made a simple example for you and uploaded it to http://zk.zonax.net/Random-line-example.zip. You just have to make sure the "file()" function is accepted by your server. If this doesn't work let me know and i will find a solution that works for your server.
(It worked for me..)

Thats a nice question, i made a simple example for you and uploaded it to http://zk.zonax.net/Random-line-example.zip. You just have to make sure the "file()" function is accepted by your server. If this doesn't work let me know and i will find a solution that works for your server.

(It worked for me..)
05-11-2007 - 12:34
Thanks, it works, although don't fully understand the code, like s the " - 1;", the variable in square brackets, etc. i will try to look into them though, thanks.
05-11-2007 - 13:37
Hmm i will explain. The file() function read the lines into an array. So every array part is one line.
The count function reads how much lines (parts) he found in the array. But the count function tells the exact number. And the array counts the part starting from 0.
So when i have 3 lines it would be:
Array part 0: Line one
Array part 1: Line two
Array part 2: Line three
These are 3 lines, but the max number is 2, so thats why i use the -1.
The rand function takes a random number between 0 and the number count() read.
The brackets are for the array, telling which part of the array it should use. Check out php.net for more info about arrays, these are important basics
The count function reads how much lines (parts) he found in the array. But the count function tells the exact number. And the array counts the part starting from 0.
So when i have 3 lines it would be:
Array part 0: Line one
Array part 1: Line two
Array part 2: Line three
These are 3 lines, but the max number is 2, so thats why i use the -1.
The rand function takes a random number between 0 and the number count() read.
The brackets are for the array, telling which part of the array it should use. Check out php.net for more info about arrays, these are important basics
08-11-2007 - 18:49
09-11-2007 - 07:42
Yeah arrays can be pretty confusing because they start at zero, while most of us would expect one. But it's easy when you are used to it.
Page:
1
Reply to topic
Reply to topic

