Syntactic Confectionery Delight PerlMonks

### comment on

 Need Help??
Following my earlier request for assistance, I'm beginning to see the joined-up way of working that I need. It is my intention to produce modules performing the general functions of the RPG. (If possible, I'd like them to be called RPG, RPG::DND, etc.) Once I have the answer to this query, I'll go away and produce the RPG::Dice module which converts any die roll, expressed as a string ('3d6' for 'the sum of three normal dice', for example) to the appropriate set of rand calls and sends back an appropriate roll. (A side-effect of this will probably be simpler calls for specific things - such as a dice(\$n) call to roll an n-sided die.) This module will, naturally, be posted here at PerlMonks.

All well and good. The small problem here is that every discussion of modules which I've encountered either jumps in the deep end or assumes prior knowledge which I haven't got. So, I'm going to ask for help with a trivial case:

In Dungeons and Dragons Third Edition, all ability score modifiers are drawn from a single table. This table's values are trivial: given a score of n, the modifier is (n/2)-5. (ie: 8-9: -1; 10-11: 0; 12-13: +1). In the first shot at the character generator, I stupidly plugged these values into a list. Simpler, cleaner, and more transferable, I now realise, to call a function modifier(\$n) for an arbitrary value of \$n. So:
```sub modifier { int(\$_[0]/2)-5 }

(I hope that does what I said it did - I just wrote it on the fly.) The question is, how can I turn that into an element of the (as yet unwritten) Module RPG::DND, and how will the function then be called?

Thanks very much,

Tiefling, Known Lazy Bastard

```-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GAT d++ s:- a-- C++ UL P++ L++(+) E? W+(++) N+ o? K w+(--)
!O M- V? PS+ PE- Y PGP- t+ 5 X+ R+++ tv- b+++ DI++++ D+ G+ e++ h!(-) y
+?
------END GEEK CODE BLOCK------

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

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2022-05-26 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Do you prefer to work remotely?

Results (92 votes). Check out past polls.

Notices?