Posted: Sun Aug 21, 2005 6:22 pm Post subject: !fortune for mayabot
A simple code that will get your bot to fortune tell:
@names=("You will be rich", "You will find money today", "you will die soon", "Future looks hazy, ask again later", "Your going to have a baby", "You will hurt yourself in a car accident", "You will take a journey somewhere", "You will find true love", "You will have your heart broken this week", "You will recieve a great shock tomorrow", "Your friend will reveal she is pregnant", "You will die in a terrorist bombing", "You will win a contest on TV", "You will lose something special") ;
$random = rand 7 ;
&send($self, @names[$random], $username);
You can add fortunes, change them, whatever, enjoy!
Oh yes, does anyone know a working !chat !horoscope or !shutup command for Maya? If so I would be really greatful to hear it!
@names=("You will be rich", "You will find money today", "you will die soon", "Future looks hazy, ask again later", "Your going to have a baby", "You will hurt yourself in a car accident", "You will take a journey somewhere", "You will find true love", "You will have your heart broken this week", "You will recieve a great shock tomorrow", "Your friend will reveal she is pregnant", "You will die in a terrorist bombing", "You will win a contest on TV", "You will lose something special") ;
$random = rand 7 ;
&send($self, @names[$random], $username);
I wouldn't use that code for a number of reasons. You made @names and $random globals, instead make them local variables with my. rand returns a fractional value and while Perl is smart enough to use just the integer part in a list index, it's bad programming style. Use int to make sure the value is an integer. @names[$random] is incorrect usage of a list to get an item from the list. You need to use $names[$random] to get a scalar value. Finally, your use of &send( $self... means you're probably using an older version of MSN.pm, which are buggy. Get a newer one.
Also, as mat007 mentioned, all those commands as well as fortune itself have been written a dozen times, you should just use an existing one that is written properly instead of posting your own code looking for recognition.
Posted: Tue Aug 23, 2005 11:30 pm Post subject: Re: !fortune for mayabot
kayleighthorpe wrote:
@names=("You will be rich", "You will find money today", "you will die soon", "Future looks hazy, ask again later", "Your going to have a baby", "You will hurt yourself in a car accident", "You will take a journey somewhere", "You will find true love", "You will have your heart broken this week", "You will recieve a great shock tomorrow", "Your friend will reveal she is pregnant", "You will die in a terrorist bombing", "You will win a contest on TV", "You will lose something special") ;
$random = rand 7 ;
Also, you are picking a random number out of 7 (giving you a range of 0 to 6) when there are more than 7 items in your array. Every item past 7 would never be used. Instead you can get a random number out of the array's length:
Code:
my $random = int(rand(scalar(@names)));
Or better yet, get a random value right away instead of getting a number first:
Code:
my $answer = $names [ int(rand(scalar(@names))) ];