Update: As of 9:54pm EST, the problem has automagically resolved itself. Which is a tidgy bit frustrating, but hey, at least it works. I'm going to decide that the Perl gods were punishing me for the klugy method of adding functionality, and telling me to make an extension module, for goodness sake.

I'm trying to add a function to Dice.pm that will roll dice according to White Wolf's WOD rules and return the number of successes. I've succeeded in creating a function that does this (roughly, anyway); my problem now is that I get a "roll_whitewolf is not exported by module Games::Dice.pm" error. I can't figure out why.

Here's the altered Dice.pm, minus perldoc. My function is roll_whitewolf:

package Games::Dice; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not expo +rt # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT_OK = qw( roll roll_array roll_whitewolf ); $VERSION = '0.02'; # Preloaded methods go here. sub roll ($) { my($line, $dice_string, $sign, $offset, $sum, @throws, @result); $line = shift; return undef unless $line =~ m{ ^ # beginning of line ( # dice string in $1 (?:\d+)? # optional count [dD] # 'd' for dice (?: # type of dice: \d+ # either one or more digits | # or % # a percent sign for d% = d100 ) ) (?: # grouping-only parens ([-+xX*/bB]) # a + - * / b(est) in $2 (\d+) # an offset in $3 )? # both of those last are optional }x; # whitespace allowed $dice_string = $1; $sign = $2 || ''; $offset = $3 || 0; $sign = lc $sign; @throws = roll_array( $dice_string ); return undef unless @throws; if( $sign eq 'b' ) { $offset = 0 if $offset < 0; $offset = @throws if $offset > @throws; @throws = sort { $b <=> $a } @throws; # sort numerically, de +scending @result = @throws[ 0 .. $offset-1 ]; # pick off the $offset + first ones } else { @result = @throws; } $sum = 0; $sum += $_ foreach @result; $sum += $offset if $sign eq '+'; $sum -= $offset if $sign eq '-'; $sum *= $offset if ($sign eq '*' || $sign eq 'x'); do { $sum /= $offset; $sum = int $sum; } if $sign eq '/'; return $sum; } sub roll_array ($) { my($line, $num, $type, @throws); $line = shift; return undef unless $line =~ m{ ^ # beginning of line (\d+)? # optional count in $1 [dD] # 'd' for dice ( # type of dice in $2: \d+ # either one or more digits | # or % # a percent sign for d% = d100 ) }x; # whitespace allowed $num = $1 || 1; $type = $2; $type = 100 if $type eq '%'; @throws = (); for( 1 .. $num ) { push @throws, int (rand $type) + 1; } return @throws; } sub roll_whitewolf { my ($pool, $diff, $crits) = @_; my @rolls; my $successes = 0; my $tens = 0; return undef if (!$pool || !$diff); @rolls = roll_array($pool . 'd10'); foreach (@rolls){ if ($_ == 1){ $successes--; $tens-- if ($tens > 0); } elsif ($_ >= $diff){ $successes++; $tens++ if ($_ == 10); } } if ($crits && $tens != 0) { $successes += roll_whitewolf($tens, $diff, ''); } return $successes; } 1;

And here's the driver program:

#!/usr/bin/perl use strict; use warnings; use Games::Dice 'roll', 'roll_array', 'roll_whitewolf'; print roll_whitewolf(10, 8, 'yes');

Which produces this error message:

"roll_whitewolf" is not exported by the Games::Dice module Can't continue after import errors at dice.test.pl line 4 BEGIN failed--compilation aborted at dice.test.pl line 4.

In reply to Dice.pm - I'm doing it wrong, somehow. by pobocks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.