Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-10-2012, 10:11 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

you can't have two subroutines with the same name in the same namespace in perl. only the last one ends up being used. if you want to check your scripts for compilation errors while writing them, add these lines at the top and run then from a command line, instead of using them from within the emulator:

Code:
use strict;
use warnings;
when you run your script from within the emulator, you'll most likely need to either remove the additional lines listed above or add the following to get them to run:

Code:
no strict 'vars';
if you were to add those lines to your script, you'd see a message similar to this one, indicating something likely isn't working as you expected it to:

example_script.pl
Code:
use strict;
no strict 'vars';
use warnings;

use constant {
    TRUE  => 1,
    FALSE => 0
};

sub conditionMet_1 {
    my $bool = defined($_[0]) ? shift : FALSE;
    print "DEBUG: checking conditionMet_1($bool)\n";
    return $bool;
}

sub conditionMet_2 {
    my $bool = defined($_[0]) ? shift : FALSE;
    print "DEBUG: in checking conditionMet_2($bool)\n";
    return $bool;
}

sub EVENT_ARBITRARY {
    # checking for TRUE(1) returned in both conditions
    # second condition is not checked if first fails
    if ( conditionMet_1(shift) && conditionMet_2(shift) ) {
        print "DEBUG: both conditions passed\n";
    }
    else {
        print "DEBUG: both conditions did not pass\n";
    }
}

sub EVENT_ARBITRARY {
    # same as before, but checking for FALSE on either condition
    # since this subroutine has the same name and is last in the list, it is used
    print "DEBUG: in second defintion of EVENT_ARBITRARY\n";
    if ( !conditionMet_1(shift) || !conditionMet_2(shift) ) {
        print "DEBUG: both conditions did not pass\n";
    }
    else {
        print "DEBUG: both conditions passed\n";
    }
}

EVENT_ARBITRARY(FALSE, TRUE);
output:
Code:
C:\EQEmu\sandbox>perl test_conditionals.pl
Subroutine EVENT_ARBITRARY redefined at test_conditionals.pl line 34.
DEBUG: in second defintion of EVENT_ARBITRARY
DEBUG: checking conditionMet_1(0)
DEBUG: both conditions did not pass
command-line debugging will also let you know when you have things like missing brackets, semicolons, or any other major syntax issues.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 05:49 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3