Alternative to nested conditional statements

I'm trying to design a random character generator for GURPS. All melee weapons in GURPS do damage based on strength.

I need to come up with a way that, after strength is generated by a table, I can compare the strength that was generated and call the correct amount of damage from another table. I was futilely trying to do this with nested conditionals until I saw in the help file that conditionals couldn't be nested.

Any ideas??

By the way, this program ROCKS! 8-)

Gilb°ne

Comments

  • Never mind, I think I figured it out.

    WOOHOO!

    Gilb°ne
  • Hi Gilbone,

    Can you post your solution? Sounds like what you did would have a lot of applications in other tables.

    Cheers,
  • Gilbone as you requested I added my GURPS NPC Generator to my site. Here is the NBOS Forum post.

    Sorry it took so long!

    It is not perfect yet (or completed), but it works nicely

    Here is how I did the weapon tables based on Strenght. I would like to know how you did yours.
    Table: Weapons
    [when] {$ST} > 1 [do]<b>Whip:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]-2} cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+1} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 1 [do]<b>Unarmed:</b> Kick: [#{$ST} ThrustDamage][#{$ST} ThrustDamageModifier] cr; SL: {!({$DX}-2) + {[$SL]}}; Punch: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier]-1} cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3}; SL: {!{$DX} + {[@SL&;#93;}}[end]
    [when] {$ST} > 4 [do]<b>Dagger:</b> Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] -1} imp; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93;<li>[#6 Rangedweapons]</li> [end]
    [when] {$ST} > 4 [do]<b>Bone Knife:</b> Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +1} cut; Reach: C Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 4 [do]<b>Small Sword:</b> Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +1} imp; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}) + {[@SL&;#93;}} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 4 [do]<b>Small Knife:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]-3} Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier]} imp; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3} [@QualityWeapons&;#93;<li>[#5 Rangedweapons]</li>[end]
    [when] {$ST} > 4 [do]<b>Rope Dart:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]-1} cr; Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier]-1} imp; Reach: 1-4; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+1} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 4 [do]<b>Chain Whip:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier] + {1d4}} cr; Reach: 1-4; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+1} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 4 [do]<b>Knife-Wheel:</b> Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +1} cut; Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] -1} imp; Reach: C; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 4 [do]<b>Stiletto:</b> Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] -1} imp; Reach: C; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 4 [do]<b>Short Baton:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]-1} cr; Thrust: [#{$ST} ThrustDamage][#{$ST} ThrustDamageModifier] cr; Reach: C,1 Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+2}; SL: {!{$DX} + {[@SL&;#93;}} [@{1d3} QualityWeapons][end]
    [when] {$ST} > 5 [do]<b>Large Knife:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]-2} Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier]-1} imp; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3} [@QualityWeapons&;#93;<li>[#16 Rangedweapons]</li>[end]
    [when] {$ST} > 6 [do]<b>ShortStaff:</b> Swung: [#{$ST} SwingDamage][#{$ST} SwingDamageModifier] cr; Thrust: [#{$ST} ThrustDamage][#{$ST} ThrustDamageModifier] cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3}; SL: {!({$DX}-1) + {[@SL&;#93;}} [@{1d3} QualityWeapons][end]
    [when] {$ST} > 6 [do]<b>Quarterstaff:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]+2} Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +1} cr; Reach: 1,2 Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+5};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 7 [do]<b>Hatchet:</b> [#{$ST} SwingDamage][#{$ST} SwingDamageModifier] cut, Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3}; Acc 1; Range: {! {$ST} *15}/{! {$ST} *25}; SL: {!{$DX} + {[@SL&;#93;}}[@QualityWeapons&;#93;[end]
    [when] {$ST} > 8 [do]<b>Shortsword:</b> Swung: [#{$ST} SwingDamage][#{$ST} SwingDamageModifier] cut; Thrust: [#{$ST} ThrustDamage][#{$ST} ThrustDamageModifier] imp; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3}; SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 8 [do]<b>Spear:</b> Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +2} imp; Thrust (2 hands): [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +3} imp; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93; [end]
    [when] {$ST} > 9 [do]<b>Broadsword:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]+1} cr; Thrust: [#{$ST} ThrustDamage][#{$ST} ThrustDamageModifier] cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3}; SL: {!({$DX}-1) + {[@SL&;#93;}} [@{1d3} QualityWeapons][end]
    [when] {$ST} > 10 [do]<b>Small Mace:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]+2} cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3}; SL: {!({$DX}-1) + {[@SL&;#93;}} [@{1d3} QualityWeapons][end]
    [when] {$ST} > 10 [do]<b>Bastardsword:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]+1} cut; Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +1} cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93; [end]
    [when] {$ST} > 10 [do]<b>Axe:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]+2} cut; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93; [end]
    [when] {$ST} > 10 [do]<b>Jian:</b> Swung: [#{$ST} SwingDamage][#{$ST} SwingDamageModifier] cut Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier]+1} imp; Reach: 1,2 Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3} [@QualityWeapons&;#93;[end]
    [when] {$ST} > 11 [do]<b>Mace:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]+3} cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3} SL: {!({$DX}-1) + {[@SL&;#93;}} [@{1d3} QualityWeapons][end]
    [when] {$ST} > 11 [do]<b>Morningstar:</b> Swung: [#{$ST} SwingDamage]{!  [#{$ST} SwingDamageModifier]+3} cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3}; SL: {!({$DX}-1) + {[@SL&;#93;}} [@{1d3} QualityWeapons][end]
    [when] {$ST} > 12 [do]<b>Greatsword:</b> Swung: [#{$ST} SwingDamage]{! [#{$ST} SwingDamageModifier]+3} cut; Thrust: [#{$ST} ThrustDamage]{! [#{$ST} ThrustDamageModifier] +2} cr; Parry: {! floor ((({$DX}-1) + {[@SL&;#93;})/2)+3};SL: {!({$DX}-1) + {[@SL&;#93;}} [@QualityWeapons&;#93; [end]
    EndTable:
    
  • I recommend nesting tables. when-do's are consuming in code. I'm writing an encounter table that is dependant on game system.

    I used this format: [@[@encounter]] in every game system specific table to avoid 1000s of when-do's for each game system encounter table. The result is if [@encounter] part of that statement call resulted in "orcs" then that statement would actually be seen as [@orcs] by IPP and run the game system specific orcs table. Thus I only have one statement rather than many when-do's.
  • This is what I did, and it's far from complete. I started by downloading one of Highland Piper's quite extensive files, which I studied and learned from. Many thanks for that HP. I haven't gotten as far as I would like to, even forgot about Inspiration Pad for a bit, but I've recently gotten back into it (just in the last few days).

    I just made a file that sets the thrust and swing damage for each level of strength from level 1 to level 22 and I call that info from a very slightly tweaked version of Highland Piper's Bandit Generator. Most of the functionality of HPs code is disabled right now and it only makes archers. If he gives me the ok I'll post that part too.

    But note that I leave the actual weapon damage up to the user to determine, all my code does is give the TH/SW damage based on ST. It also determines whether the NPC has 0, 1 or 2 levels of Striking ST.

    This file alone won't generate anything useable.
  • Hi all,

    I'd like to confirm the nested table approach - it's waaaaay more efficient than using conditionals. I have a table that generates wilderness terrain based on the climate the user selects. This thread saved me a bunch of extra coding.

    Here's a quick and dirty example:
    Formatting: html
    Header:<strong>Wilderness Planner for Atlas-sized Hex Maps</strong>
    Prompt: Climate {Arctic|Sub-arctic|Temperate|Sub-tropical|Tropical} Temperate
    Table: Wilderness
    <ul><li> &
    [@{$prompt1}Terrain&;#93; &
    </li></ul>
    # TERRAIN SUBTABLES
    # -------------------------
    Table: ArcticTerrain
    Type: Lookup
    Roll: 1d8
    1-8:Arctic wilderness terrain here
    # -------------------------
    Table: Sub-arcticTerrain
    Type: Lookup
    Roll: 1d8
    1-8:Sub-arctic wilderness terrain here
    # -------------------------
    Table: TemperateTerrain
    Type: Lookup
    Roll: 1d8
    1-8:Temperate wilderness terrain here
    # -------------------------
    Table: Sub-tropicalTerrain
    Type: Lookup
    Roll: 1d8
    1-8:Sub-tropical wilderness terrain here
    # -------------------------
    Table: TropicalTerrain
    Type: Lookup
    Roll: 1d8
    1-8:Tropical wilderness terrain here
    

    I'm sure this is obvious to the old salts on the list, but hopefully it'll save time for newbies. ;)

    Cheers,

Leave a Comment