User Control Panel
Advertisements

HELP US, HELP YOU!

My Module: SBAI

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review
View unanswered posts
Author Message
dvondrake
Not Yet a God
Not Yet a God


Joined: 11 Mar 2004
Posts: 314
Location: El Paso, Texas
Reputation: 32.6Reputation: 32.6Reputation: 32.6

PostPosted: Tue Nov 09, 2004 2:12 am    Post subject: Reply with quote

Hey,
I'm currently making a module called SBAI (Smart Bot Artificial Intelligence) to enhance the way you ask bots to do commands. Example: Instead of "!menu", you'd say "Show me the menu".
Yes, seems very pointless, but heck, you can do more with it if you use your immagination. It's also for fun. Razz

Anyways, my code kinda works.. It just doesnt relay the response back to bot.pl so it can send it to the user.

Here's my code.

**EDIT: Took it out because everyone was making fun of me. Now nobody gets the cookie.**

Not quite sure what's wrong with it.
First person to help gets a cookie. Smile

Thanks in advance,
-Doug
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Tue Nov 09, 2004 2:27 am    Post subject: Reply with quote

I see a number of problems:

You should always use strict; and use warnings;, especially when you're trying to create a new module.

You're not using my on several variables, which will only cause you lots of problems down the line.

You're using a variable $sbai in many places, but where is it coming from? I suspect, you think $sbai is a reference to your object, but this is the class code, where are you actually creating the object?

None of the methodes in your SBAI package ever get a reference to the SBAI object. The first line of any object oriented method (function) should be my $this = shift;. Sometimes, people use $self.

What is in ./smartbot.dat that you are doing?

Code:
my @greeting = ("Hi", "Yo", "Sup", "Jo", "J0", "Hello", "Hio", "Hiho", "Hey");<br />my $greeting = @greeting;


What do you expect that code to do?
Back to top
dvondrake
Not Yet a God
Not Yet a God


Joined: 11 Mar 2004
Posts: 314
Location: El Paso, Texas
Reputation: 32.6Reputation: 32.6Reputation: 32.6

PostPosted: Tue Nov 09, 2004 2:54 am    Post subject: Reply with quote

I have tried using strict, but it messes up my hashes. (wants me to put "my" in front of $username in my hash: $sbai->{$username})

The ones I'm not using my on are the hashes.

I've tried that, but it doesnt seem to work.

With the dat file, I save the response for later use in the subs, so I can send it to the bot.pl as a response.

That peice of code lists all the greeting to be used as greetings in the "Chatty Binder" section.

Please help, I'm stuck. -.-
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Tue Nov 09, 2004 3:08 am    Post subject: Reply with quote

You use my in front of variable names when you declare them, not when you use them. My won't mess up your hashes - you get the errors and warnings for a reason.

What did you edit in your code? Did you add my $sbai = shift; to your new method? That's not where you want it, you want it in all of the other methods.

And why are you creating an object that has an array instead of a hash?

Code:
sub new {<br />  my $class = shift;<br />  my $sbai = shift;<br />  # notice it's an array, not a hash<br />  return bless [], $class;<br />}


Why an array and not a hash?

Where did you find this code? Or did you really make it from scratch?
Back to top
aurora_131
Young One
Young One


Joined: 07 Mar 2004
Posts: 66
Location: Melbourne, victoria.
Reputation: 27.7Reputation: 27.7Reputation: 27.7

PostPosted: Tue Nov 09, 2004 11:11 am    Post subject: Reply with quote

where does $rawcom and $com1 come from?

Code:
$sbai = do "./smartbot.dat";<br />if ($sbai->{$com} eq $com1) {<br />my $rawc2r = $2;


where is the wild card 2 in play? and how do you know what $com is?

You're referring to alotta variables that might not exist...

Code:
$gout = $messages[int rand scalar @greeting];

should be
Code:
$gout = $greeting[int rand scalar @greeting];

You do this because you call a random line in the array, you seem to be calling it a variable name...

good luck though, a bit of hard work and this might be nice.
Back to top
farkie
God Like
God Like


Joined: 15 Nov 2003
Posts: 673

Reputation: 3.4Reputation: 3.4Reputation: 3.4

PostPosted: Tue Nov 09, 2004 7:47 pm    Post subject: Reply with quote

surely it would be easier to do:

Code:
if ($msg =~ /^show me the menu/) {<br />$self->sendmsg("Here is the menu: \n# the menu....");<br />}
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Tue Nov 09, 2004 11:00 pm    Post subject: Reply with quote

This is a pretty good example of code that hasn't been tested even a little bit.

When building modules, I myself, like to do them in little bits. I take the smallest part and grow the module form there. Generaly that means makeing two files, the module file, and a test file. The test file is just the minimal amount needed to use that module. They both start with just a few lines, then as functions are added to the module, i add code to test those functions in the test script. In the end you have a working module, that you know every peice of is constantly tested, and all along the route you have working code.

Your code on the other hand looks like you had an idea, and tried to program the whole thing all at once. Doing it in little bits and constantly testing will allow you to catch errors like "if ($msg = @k1) {" much earlier. That bit of code sets $msg equal to the length of the array k1. Which i'm guessing is not what you want it to do.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group