Thread: Perl Issue
View Single Post
  #18  
Old 12-04-2012, 07:17 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

here's an (untested except for syntax) example of how looping could greatly reduce your code, and due to that, the chance of syntax errors. i added comments directing you to information in the perl documentation (which i sent you links to in my first response) that applies to what i have done here.

Code:
# subroutines covered @ http://perldoc.perl.org/5.12.4/perlsub.html
sub customRoutine {
    # private variables covered @ http://perldoc.perl.org/5.12.4/perlsub.html#Private-Variables-via-my%28%29
    my $itemcount  = shift;
    # lists covered @ http://perldoc.perl.org/5.12.4/perldata.html#List-value-constructors
    # range operator covered @ http://perldoc.perl.org/5.12.4/perlop.html#Range-Operators
    my @validitems = (150009..150107);
    # foreach loop covered @ http://perldoc.perl.org/5.12.4/perlsyn.html#Foreach-Loops
    foreach my $itemid (@validitems) {
        # note: $itemcount is already a hashref, so we don't pass it like we did before
        if (plugin::check_handin($itemcount, $itemid => 1)) {
            quest::say("Well done, $name, you are now level 1 with an upgraded ring.");
            quest::level(1);
            # your reward item always seemed to be the itemid of the handin +1, so this does that
            quest::summonitem($itemid+1, 1);
            quest::ding();
        }
    }
}

sub EVENT_ITEM {
    if ($ulevel > 64) {
        # pass by reference covered @ http://perldoc.perl.org/5.12.4/perlsub.html#Pass-by-Reference
        customRoutine(\%itemcount);
    }
    else {
        quest::say("You're not level 65 yet, $name.");
    }
    plugin::return_items(\%itemcount);
}
Reply With Quote