#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Help with Dictionary Tables

edited November 2013
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 = &#91;|male |female&#93;
Set: gendermod = &#91;@gendermod&;#93;
Set: age = &#91;@age&;#93;
Set: AgeMod = &#91;#{age} AgeMod&#93;

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

Table: gendermod
&#91;when&#93; {gender} = male &#91;do&#93; 10 &#91;else&#93; 0 &#91;end&#93;

Table: Age
Type: Lookup
Roll: 1d100
1-5:Teenage
56-75:Middle Aged
76-95:Old
96-100:Ancient

Table: AgeMod
Type: dictionary
Default: 0
Teenage: 0
Middle Age: 30
Old: 40
Ancient: 50
```

• I see whats happening. The expression
```&#91;#{age} AgeMod&#93;
```
after the substitution is being turned into something like
```&#91;#Middle Aged AgeMod&#93;
```
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 &#91;#{Prompt1} AgeModTable&#93;

Table: AgeModTable
Type: dictionary
Teenage:0
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
```

```#Gender and Age Testing

Set: Gender = &#91;|male |female&#93;
Set: GenderMod = &#91;@GenderMod&;#93;
Set: Age = &#91;@Age&;#93;
Set: AgeMod = &#91;@AgeMod&;#93;

Table: Test
The gender is {Gender}. The gender modification is {GenderMod}.\nThe age is {Age}. The age modification is {AgeMod}.

Table: gendermod
&#91;when&#93; {gender} = male &#91;do&#93; 10 &#91;else&#93; 0 &#91;end&#93;

Table: Age
Type: Lookup
Roll: 1d100
1-5:Teenage
56-75:MiddleAged
76-95:Old
96-100:Ancient

Table: AgeMod
&#91;#{Age} AgeModTable&#93;

Table: AgeModTable
Type: dictionary
Teenage:0
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 = &#91;|male |female&#93;
Set: GenderMod = &#91;@GenderMod&;#93;
Set: Age = &#91;@Age&;#93;

Table: Test
The gender is {Gender}. The gender modification is {GenderMod}.\nThe age is {Age}. The age modification is {AgeMod}.

Table: gendermod
&#91;when&#93; {gender} = male &#91;do&#93; 10 &#91;else&#93; 0 &#91;end&#93;

Table: Age
Type: Lookup
Roll: 1d100
1-5:Teenage {AgeMod == 0}
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 = &#91;|male |female&#93;
Set: GenderMod = &#91;@GenderMod&;#93;
Set: Age = &#91;@Age&;#93;
Set: AgeMod = &#91;@AgeMod&;#93;
```
Remove the spaces like
```Set: Gender =&#91;|male |female&#93;
Set: GenderMod =&#91;@GenderMod&;#93;
Set: Age =&#91;@Age&;#93;
Set: AgeMod =&#91;@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.