Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: (ichimunki) Re (tilly) 1: Dice::Dice

by salvadors (Pilgrim)
on Jan 08, 2001 at 02:11 UTC ( [id://50393]=note: print w/replies, xml ) Need Help??


in reply to (ichimunki) Re (tilly) 1: Dice::Dice
in thread Dice::Dice

By carefully abusing list vs. scalar context, the same method can be made to return a single roll or a list of several rolls

Why would this be abusing context? That is exactly what wantarray is for ...

Also, as an amusing trick, I'd like to see an OppositeFace () method.

sub opposite_face { my $self = shift; return $self->{size} - $self->{face} + 1; }

Tony

Update: DOH!

Replies are listed 'Best First'.
Re: Re: (ichimunki) Re (tilly) 1: Dice::Dice
by ichimunki (Priest) on Jan 08, 2001 at 02:19 UTC
    Re: Context: I know it's not really abuse. Poor choice of words.

    That should probably be  return $self->{size} + 1 - $self->{face};. Yours returns 13 on a six-sider with a six up. The answer is one. Of course, we also need a sanity check that it's an even number of sides not equal to 4 (since four sided dice are pyramid shaped).

    Note: I think I am a little too into dice. :) Update: the opposite face formula in the preceding post is correct at this time. I still maintain a need to sanity check whether the die has opposing face.
      Update: This post is not relevant.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://50393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-03-28 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found