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------
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.