EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Perl Issue (https://www.eqemulator.org/forums/showthread.php?t=36069)

kmra247 12-04-2012 05:17 PM

I don't see the need to be rude, as I said, I'm new to Perl, I apologize for not knowing everything. But in the saylink, I didn't want him to say "Ring of Armageddon" in purple text and make you click on it, I wanted him to link the item to where you could click on it and see the stats. Like a person linking an item in /ooc and you click on it, except an NPC. But, I guess I can Google it...

Edit: I found the thing it would be "my $roa = quest::varlink(150009);". Thanks to everyone who helped.

sorvani 12-04-2012 05:46 PM

i balance my helpfulness. you were told multiple times how to check your perl script for syntax errors. You apparently never did it based on the errors in the last one you posted.
That said I still fixed your script. What Cary is referring to is your script is horribly long and repetitive with the only thing changing being an incrementing number. That is the classic best case for a FOR loop. your entire check_handin logic section could shrink to about 15 lines of code.

c0ncrete 12-04-2012 07:17 PM

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);
}


Zamthos 02-22-2013 09:34 PM

This was almost two months ago, no need to necro old posts. ;D

c0ncrete 02-22-2013 09:40 PM

if you haven't caught on yet, he's simply parroting exactly what someone else has said in the thread. :p

Zamthos 02-22-2013 09:55 PM

Yeah, I noticed, haha.


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

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.