Help with Dictionary Tables

I'm trying to use a dictionary table to assign a modifier based on gender and age for an NPC generator I'm working on. Basically I'm trying to weight the tables for hair color and baldness so the older the character is the more likely they will have grey or white hair, and males have more of a chance of thinning hair than females. I am not having a problem with the gender modifier, but I'm trying to use the dictionary table to assign the age modifier and I'm getting "(missing)" where the age modifier should be. I'm sure it is a fairly simple syntax issue, but I've gone through the documentation and I can't figure out what I'm doing wrong. Any help will be appreciated. My code follows:
#Gender and Age Testing

Set: gender = [|male |female]
Set: gendermod = [@gendermod&;#93;
Set: age = [@age&;#93;
Set: AgeMod = [#{age} AgeMod]

Table: Test
The gender is {gender}. The gender modification is {gendermod}.\nThe age is {age}. The age modification is {AgeMod}.

Table: gendermod
[when] {gender} = male [do] 10 [else] 0 [end]

Table: Age
Type: Lookup
Roll: 1d100
1-5:Teenage
6-15:Young Adult
16-55:Adult
56-75:Middle Aged
76-95:Old
96-100:Ancient

Table: AgeMod
Type: dictionary
Default: 0
Teenage: 0
Young Adult: 10
Adult: 20
Middle Age: 30
Old: 40
Ancient: 50

Comments

  • I see whats happening. The expression
    [#{age} AgeMod]
    
    after the substitution is being turned into something like
    [#Middle Aged AgeMod]
    
    That wouldnt be valid because its trying to lookup the value 'Middle' in the 'Aged' table, which obviously doesn't exist. To use a substitution like that, you'd need a key without any spaces, like
    MiddleAged
    
    What you might do is assign the human friendly text to a variable and output that, but keep the lookup keys a single word.
  • I played with the console and realized that was probably the problem. I wrote a second simple dictionary table test using a prompt command, and it works fine
    Prompt: Choose an age category {|Teenage|YoungAdult|Adult|MiddleAge|Old|Ancient} Adult
    
    Table: Test
    The age is {Prompt1}; the age modification is [#{Prompt1} AgeModTable]
    
    
    Table: AgeModTable
    Type: dictionary
    Teenage:0
    YoungAdult:10
    Adult:20
    MiddleAge:30
    Old:40
    Ancient:50
    

    So I went in and did exactly as you suggested and removed the spaces from the first table I wrote, but I'm still having the same problem. Here is what the console says upon running the table:
    Table: GenderMod
     Table: Age
     Table: AgeMod
      Table: MiddleAged AgeModTable
      Missing Table: MiddleAged AgeModTable
    

    For reference, here is the latest version of the table code:
    #Gender and Age Testing
    
    Set: Gender = [|male |female]
    Set: GenderMod = [@GenderMod&;#93;
    Set: Age = [@Age&;#93;
    Set: AgeMod = [@AgeMod&;#93;
    
    Table: Test
    The gender is {Gender}. The gender modification is {GenderMod}.\nThe age is {Age}. The age modification is {AgeMod}.
    
    Table: gendermod
    [when] {gender} = male [do] 10 [else] 0 [end]
    
    Table: Age
    Type: Lookup
    Roll: 1d100
    1-5:Teenage
    6-15:YoungAdult
    16-55:Adult
    56-75:MiddleAged
    76-95:Old
    96-100:Ancient
    
    Table: AgeMod
    [#{Age} AgeModTable]
    
    Table: AgeModTable
    Type: dictionary
    Teenage:0
    YoungAdult:10
    Adult:20
    MiddleAge:30
    Old:40
    Ancient:50
    
  • Not sure whats going on there. Until I can dig into seeing why its doing that, you can also do something like this:
    #Gender and Age Testing
    
    Set: Gender = [|male |female]
    Set: GenderMod = [@GenderMod&;#93;
    Set: Age = [@Age&;#93;
    
    Table: Test
    The gender is {Gender}. The gender modification is {GenderMod}.\nThe age is {Age}. The age modification is {AgeMod}.
    
    Table: gendermod
    [when] {gender} = male [do] 10 [else] 0 [end]
    
    Table: Age
    Type: Lookup
    Roll: 1d100
    1-5:Teenage {AgeMod == 0}
    6-15:YoungAdult {AgeMod == 10}
    16-55:Adult {AgeMod == 20}
    56-75:MiddleAged {AgeMod == 30}
    76-95:Old {AgeMod == 40}
    96-100:Ancient {AgeMod == 50}
    

    This uses the 'quiet' assignment (the == instead of just a =) to assign associated values in a table roll.
  • ooooook, I figured out whats going on. Its the space between the = and the variables here:
    Set: Gender = [|male |female]
    Set: GenderMod = [@GenderMod&;#93;
    Set: Age = [@Age&;#93;
    Set: AgeMod = [@AgeMod&;#93;
    
    Remove the spaces like
    Set: Gender =[|male |female]
    Set: GenderMod =[@GenderMod&;#93;
    Set: Age =[@Age&;#93;
    Set: AgeMod =[@AgeMod&;#93;
    
    What it was doing was including that leading space as part of the variable, and thus screwing up the table call. I'll have to think about whether or not that behavior should change. It'll depend on how the leading text in other elements is handled.

Leave a Comment