Right, Well i was talking to cer along time ago and i was moaning about all the warnings that reloading the commads were printing out, He gave me a peice of code to shut me up:PBut i forgot to remove one i finished and now the errors have been building up so i only have my self to blame
But im missing something in my knoledge as near enough every error is the same usually like
Code:
Use of uninitialized value in string eq at Evolution_Bot_Template.pl line XXXX
But im asking to be taught how to code properly as this obviously isnt correct in the way im going about things so any help/cleaning up would be thanked.
BOT.PL
Code:
system("title .: Evolution Bot Template :.");<br /><br />use lib "./Lib";<br /><br />use MSN;<br />use LWP::Simple;<br />use Data::Dumper;<br />use MIME::Base64;<br />use CML::Util;<br />use Timer;<br /><br /><br />$timer = Timer->new;<br />$save = {};<br />$save = do("./files/save.dat");<br />#####################################-><br />$email = $save->{general}->{botsuser};<br />$pass = $save->{general}->{botspass};<br />$botsname = $save->{general}->{botsname};<br />$char = $save->{general}->{cmdchar};<br />#$SIG{__WARN__} = sub {};<br />$dot = decode_base64(" 4oCi");<br />#####################################-><br /> print"Starting Evolution Bot Template.\n\nCreated By Dazzy2004";<br /> <br /> if(!-e './files/save.dat'){<br /> print "It looks like you havent ran the setup yet.\nStarting setup now.......\n\n\n------------------------------\n";<br /> system "click to set up bot.bat";<br /> }<br /><br /> elsif (-e "lib" ne 1 || -e "stuff" ne 1 || -e "commands" ne 1 || -e "files" ne 1) {<br /><br /> print "It looks like you are missing one of the following DIR's:"<br /> . "Lib, Images, Files, Commands."<br /> . "They should have come in the zip you downloaded\n.";<br /> }<br /> print "\n\n.:Gathering Files:.\n";<br /><br /> opendir(DIR, "./files");<br /> foreach $file (sort(grep(!/^\./, readdir(DIR)))) {<br /> print " $file\n";<br /> require "files/$file";<br /> }<br /> print "============\n.:Adding Brains:.\n";<br /> closedir(DIR);<br /> opendir(DIRR, "./brains");<br /> foreach $file2 (sort(grep(!/^\./, readdir(DIRR)))) {<br /> require "brains/$file2";<br /> print" $file2";<br /> }<br /> print"\n============\n";<br /> closedir(DIRR);<br /><br /> &get_commands;<br />
edit (eric): reduced down to a smaller portion. Start small.
Joined: 03 May 2006 Posts: 2292 Location: Colorado
Posted: Sat Oct 16, 2004 12:04 am Post subject:
Okay so this is our first review, and it will probably be a little rough around the edges.
First make a copy of your working script and save it away. No reason to burn our bridges here. This way if something goes wrong you can go back to square one and try agian.
I always start script with
Code:
<br />use strict;<br />use warnings;<br />
This will cause you to fix errors as you go, instead of when they start biting you in the a$$.
I would then move the bit about loading the file, to after you check if it exists down below. That way if they don't have the file, they can go set it up, and then continue on and the bot will load it. Also add my in front of all new variables.
Code:
<br /> print"Starting Evolution Bot Template.\n\nCreated By Dazzy2004";<br /> <br /> if(!-e './files/save.dat'){<br /> print "It looks like you havent ran the setup yet.\nStarting setup now.......\n\n\n------------------------------\n";<br /> system "click to set up bot.bat";<br /> }<br /> elsif (-e "lib" ne 1 || -e "stuff" ne 1 || -e "commands" ne 1 || -e "files" ne 1) {<br /><br /> print "It looks like you are missing one of the following DIR's:"<br /> . "Lib, Images, Files, Commands."<br /> . "They should have come in the zip you downloaded\n.";<br /> }<br /><br />my $save = do("./files/save.dat");<br /><br /># some code to tell if save got loaded, and load a default if it did not.<br /><br />#####################################-><br />my $email = $save->{general}->{botsuser};<br />my $pass = $save->{general}->{botspass};<br />my $botsname = $save->{general}->{botsname};<br />my $char = $save->{general}->{cmdchar};<br />my $dot = decode_base64(" 4oCi");<br />#####################################-><br />
Thats a bit of a mouthful so far. Hopefully it will give you a starting point.
Looking forward to the next version of this! _________________ Eric256
Proud previous owner and current admin of Bot-depot.com
Joined: 03 May 2006 Posts: 2292 Location: Colorado
Posted: Sat Oct 16, 2004 3:55 pm Post subject:
Give a line it is happening on.
BTW "Use of uninitialized value in string eq at" says it all.
That means somewhere you are doing $var1 eq "some string" but $var1 is undifined. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com
Everythings done Its as clean as a wistle except me and eric are having some problems stopping the redefined errors Now its on every commands on line one ( where the { is )
Heres the sub called to reload the commands:
Code:
sub gatherCommands{<br /> my @dirs = (1..200,"chat");<br /><br /> foreach my $dir (@dirs) {<br /> opendir(DIR, "./commands/$dir");<br /> foreach my $file (sort(grep(!/^\./, readdir(DIR)))) {<br /> no warnings;<br /> delete $INC{"commands/$dir/$file"};<br /> $file =~ s/\.pl$//ig;<br /> $bot->{store}->{commands}->{$file} = do "./commands/$dir/$file.pl";<br /> }<br /> closedir(DIR);<br /> }<br /> &store;<br />}
Also while im here: Take a look at this: any reason why it should change back to {botsname}
Code:
if($msg eq '') {<br /> return '[error]Wrong Usage. You didnt give me a message to popup.';<br /> }<br /> else {<br /> $bot->{msn}->setName("Popup: $msg");<br /> $bot->{msn}->setStatus("HDN");<br /> $bot->{msn}->setStatus("NLN");<br /> sleep(1);<br /> $bot->{msn}->setName("(H)$save->{general}->{botsname}(H)") if(defined $save->{general}->{botsname});<br /> return "Popped up '$msg'";<br /> }
Joined: 06 Jan 2004 Posts: 562 Location: Netherlands
Posted: Sat Oct 23, 2004 3:44 pm Post subject:
Sidenote: No fast reply button?
I have messed around with warnings, but no luck. It either doesn't like me, or there's some bug in Perl which doesn't allow to turn off warnings for redefined subs. However, I have found a quick solution to your problem Daz,
Code:
# Preferably at the top of your main file<br />$SIG{'__WARN__'} = sub {<br /> # Stop warnings upon redefining things<br /> return if($_[0] =~ /subroutine (.*) redefined/i);<br /><br /> # Still print the rest to the prompt of course<br /> warn $_[0];<br />};