|
| Author |
Message |
Cheater Senior Member

Joined: 10 Jun 2005 Posts: 236
  
|
Posted: Tue Jul 19, 2005 9:07 pm Post subject: (\$signon_done); |
|
|
Just wondering, in my code, I have always been using this to set a callback:
| Code: | | $oscar->set_callback_signon_done(\&signon_done); |
What does the (\&signon_done) part do? I couldn't find this in the documentation or on bot-depot.
And to avoid making another thread, how do I tell my perl script to run a sub? So if I were to have something like this:
| Code: |
if ($msg eq "!menu) {
********
}
sub menu {
print "Menu";
}
|
What would I use in place of the *'s to tell it to run the menu sub (and print Menu). |
|
| Back to top |
|
 |
darkmonkey The Merovingian

Joined: 18 Apr 2004 Posts: 2557 Location: London, England
     votes: 7
|
Posted: Tue Jul 19, 2005 9:32 pm Post subject: |
|
|
$oscar->set_callback_signon_done(\&signon_done);
That makes OSCAR call sub signon_done when it's signed on.
--
if ($msg eq "!menu") {
&menu();
}
--OR--
if ($msg =~ /^!(.*?)/)
{
my $sub = $1;
&{$sub};
}
sub menu {
print "Menu";
}
Learn how to pass variables with shifts, too. _________________ ~ Josh
[ Need bot hosting on a dedicated server? PM me. ] |
|
| Back to top |
|
 |
Cheater Senior Member

Joined: 10 Jun 2005 Posts: 236
  
|
Posted: Tue Jul 19, 2005 9:42 pm Post subject: |
|
|
About passing variables with shifts, would I do:
my($var1,$var2,$var3) = @_;
And what code would I use to have it terminate the perl program (exit)? |
|
| Back to top |
|
 |
Cer Upgraded Agent

Joined: 03 Feb 2004 Posts: 3776 Location: Michigan
  votes: 4
|
Posted: Tue Jul 19, 2005 10:17 pm Post subject: |
|
|
To terminate the Perl program:
I don't think the 0 is required, but that's just what I always do.
To answer your first question about the \&signon_done, it's a coderef.
For example, when you do:
$ref = \@array
Then $ref becomes an arrayref (reference to an array).
Likewise, \%hash becomes a hashref.
As seen in darkmonkey's post, the symbol for a subroutine is &, so &signon_done is a subroutine (we'll just call it "code" for the sake of references), and when you do \&signon_done it becomes a coderef.
Basically what it does, the module keeps a copy of &signon_done within itself to call when it needs it. So in that sense, if you redefine your signon_done handler afterward, it won't change the copy the module has. So if your bot has a command to reload handlers, you'll have to define the handlers in your module object again with the \&signon_done thing. _________________ Current Site (2008) http://www.cuvou.com/ |
|
| Back to top |
|
 |
Cheater Senior Member

Joined: 10 Jun 2005 Posts: 236
  
|
Posted: Tue Jul 19, 2005 11:01 pm Post subject: |
|
|
| Thanks a ton cer. That's what I needed to know. |
|
| Back to top |
|
 |
mattaustin Sentinel

Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA
  votes: 1
|
Posted: Tue Jul 19, 2005 11:09 pm Post subject: |
|
|
| really basic perl stuff |
|
| Back to top |
|
 |
Cheater Senior Member

Joined: 10 Jun 2005 Posts: 236
  
|
Posted: Tue Jul 19, 2005 11:34 pm Post subject: |
|
|
| well, most the tutorials I view don't mention that. I thought it was what it was used for, but I wanted to make sure. |
|
| Back to top |
|
 |
Addict Not Yet a God

Joined: 21 Jan 2004 Posts: 473
   
|
Posted: Wed Jul 20, 2005 2:46 am Post subject: |
|
|
You should really read http://perldoc.perl.org before asking for help.. might be faster.. 
Last edited by Addict on Wed Jul 20, 2005 3:51 pm; edited 1 time in total |
|
| Back to top |
|
 |
darkmonkey The Merovingian

Joined: 18 Apr 2004 Posts: 2557 Location: London, England
     votes: 7
|
Posted: Wed Jul 20, 2005 8:50 am Post subject: |
|
|
TCS: IT'S PERLDOC, WITHOUT THE "S". ARRRRGH. And the same in your signature >_< _________________ ~ Josh
[ Need bot hosting on a dedicated server? PM me. ] |
|
| Back to top |
|
 |
Addict Not Yet a God

Joined: 21 Jan 2004 Posts: 473
   
|
Posted: Wed Jul 20, 2005 3:53 pm Post subject: |
|
|
| DM: Oh shhhhhhhhhut uppp it was a simple mistake. I edited it now it works. |
|
| Back to top |
|
 |
|