I'm slightly confused (done a lot of RPGing, very little of that D&D) about what the actual desired outcome is.
It looks to me that either given a global nSTR value there's a global nSTRm that can be derived (as some kind of "mStatInit()" function to (re)set the globally defined version, or just as a calculation within the constant declaration, immediately after the constant-declaration of nSTR), or you're going to be asking for a new nSTRm for various different nSTRs (in which case, function it all the way, with a "nSTRm = CalcnSTRm(nSTR)" equivalent).
And... the if bit? At first I thought it was there to "avoid a division by zero", until I read it carefully and saw that this would never be the case and it
wasn't there to give a specific defined value for what would have been an undefined (or NaN) result.
Without the special case of the value 9 (which I'll highlight, in the following lists), as far as I can tell the input nSTR values of 7, 8,
9, 10, 11, 12 produce calculated values of -1.5, -1,
-0.5, 0, 0.5, 1, respectively, which I presume by casting to the nSTRm with its (presumably) integer type would become -2, -1,
-1, 0, 1 and 2, accordingly. (Round it to nearest, as classically required? Or does it round it towards zero? And which behaviour do the sourcebooks require? These questions may need to be asked, if you don't already know.) Is the confusion as to rounding the reason for the special case for 9?
(Given that I'm half certain that stats don't
naturally dip beneath 8 in the D&D system, I include the base value of 7 for extrapolation purposes only... But I'm sure a good case of poisoning could bring that value into range if it is to be a dynamic range for both source and calculated versions in the nSTR family (and the other-stat equivalent ones, of course).)
edit: Actually, ninjaed, as I've just now read Mephisto's message, which makes me think he knows something about both the D&D system and is also certain about the natural behaviour of this dialect, where I'd tend to always make sure by using explicit (and hopefully obvious-to-future-reader) methods, regardless of what language I'm currently using.[1][1] Doesn't stop me from doing silly things like the following, and all without any comments...
sub NextPerm {
for my $i (0..$#_) {
return 1 if $_[$i]++<$MAX;
$_[$i]=$MIN;$i++;
} # END for my $i (0..$#_) {
return 0;
}
I suppose I could[2] ask for answers on a postcard if you can work out what that's supposed to be doing (and how it used)...
And point out the the small mistake that I've just seen which doesn't actually cause it to go wrong, but is a vestigial element left over from a prior re-write, and
could have easily caused unexpected problems if I hadn't inadvertently made it not matter at all in this situation.
[2] Not that I am doing, but as I'm trying to demonstrate my sometimes bad coding I really have no reason to prevent you from reply about this, anyway, should you so wish!