Day 003: SGN
#18
I've found SGN to frequently be quite useful. One of my better success stories in the use of SGN was this little snippet from a role playing character generator.

Code: (Select All)
FUNCTION Bonus% (mode AS INTEGER, stat AS INTEGER, PCin AS INTEGER)
    ' Returns the multiplier for characteristic based attributes.
    ' as per the following table.
    '            Characteristic Value {char(stat, PCin).value}
    '           1-4     5-8     9-12    13-16   17-20   each +4
    'Mode
    'Pri [ 1]   -2      -1       0        1       2       +1
    'Pri-[-1]    2       1       0       -1      -2       -1
    'Sec [ 2]   -1       0       0        0       1       +1
    'Sec-[-2]    1       0       0        0      -1       -1
    ' Use straight for hit points and multiply by 5 for skill category modifiers.
    ' mode: 1= primary  2= secondary  -1= negative primary  -2= negative secondary
    ' stat passes the index number of the characteristic in question
    ' PCin passes the PC index usually ActPC but also a loop control from
    ' Delete_PC removal routine
    v% = (_CEIL(char(stat, PCin).value / 4) - 3) * SGN(mode)
    Bonus% = v% - (ABS(mode) - 1) * SGN(v%)
END FUNCTION 'Bonus%

While it doesn't look like much to a casual observer, those two equations essentially replaced 16 lines of SELECT CASE block. Oh yes, and _CEIL was new to me when this was written too.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply


Messages In This Thread
Day 003: SGN - by SMcNeill - 11-08-2022, 12:34 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 01:39 PM
RE: Day 003: SGN - by SMcNeill - 11-08-2022, 02:29 PM
RE: Day 003: SGN - by Jack - 11-08-2022, 02:28 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 03:13 PM
RE: Day 003: SGN - by SMcNeill - 11-08-2022, 03:50 PM
RE: Day 003: SGN - by Jack - 11-08-2022, 03:43 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 04:11 PM
RE: Day 003: SGN - by SMcNeill - 11-08-2022, 05:47 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 05:57 PM
RE: Day 003: SGN - by mnrvovrfc - 11-08-2022, 04:51 PM
RE: Day 003: SGN - by bplus - 11-08-2022, 08:20 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 08:28 PM
RE: Day 003: SGN - by bplus - 11-08-2022, 09:37 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 09:43 PM
RE: Day 003: SGN - by bplus - 11-08-2022, 09:53 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 10:23 PM
RE: Day 003: SGN - by OldMoses - 11-09-2022, 07:18 AM
RE: Day 003: SGN - by Pete - 11-09-2022, 08:46 AM



Users browsing this thread: 8 Guest(s)