Setting and Passing Variables to Sub-Tables

I have a master table in which each line calls a slave table with 12 lines in it. Most of the time I want the line selection in the slave table to be based on the roll of a d12, but for one of the lines in the master table I need to modify the selection made from the slave table by a factor of -5, so I'm using a variable called DM to hold the selection value to be passed to the slave table via a sub-table pick.
As I don't want to make a call on the slave table using a negative number or zero I have an "if" statement in the master table to set any value of DM below 1 to a minimum of 1.

I have two problems. The first is that I need to stop the calculations in line 3 of the master table being displayed on-screen. I understand that a double equals sign (==) will do this and it works for the first two expressions, but when I try a double equals sign in the "if" statement I get an invalid expression error.

The second issue is that when I call the slave table using [#{DM} Slave] it doesn't use the adjusted variable DM to select the appropriate line in the slave table.

(The example below is not the actual table, but a simplified one to show my code)

Set: DM=1

Table: Master
1: [@Slave]
2: [@Slave]
3: {DM=={1d12}}{DM==DM-5}{if({DM >= 1}, {DM == DM}, {DM == 1})}[#{DM} Slave]

Table: Slave
Type: Lookup
Roll: 1d12

Any advice would be much appreciated.


  • I don't know if you can use "if" that way. It's a mathematical operation that picks one or the other value, not a execution branch -- that's what "when" if for. This works:

    {DM=={1d12}}{DM==DM-5}{DM=={if({DM >= 1},DM,1)}}[#{DM} Slave]

    You could also do it this way:

    {DM=={1d12}}{DM==DM-5}[when]{$DM}<1[do][DM==1][end][#{DM} Slave]

  • edited November 2018

    Also, if you don't want choice #1 on Table: Slave to be selected 6x as often as choices 2 - 7, then you could just use

    3: [#{1d7} Slave]

    for line 3 of Table: Master.

    The way it stands with the "when" or "if" statements, you will wind up with a massively disproportionate lookup values of "1". That may be intended... choice 1 on the slave table may be "you find nothing", and it may be intended to occur half the time (on a roll of 1 to 6 on a d12).

    Here's a working test code for the 1d7 equally weighted solution. In it, the Set: DM and DM==5 really have no effect and are not needed. But, they are in there in case DM is a variable that dynamically set by another routine or user input.

    ; DM.ipt
    ; created 11/30/2018 1:35:40 PM
    Set: DM=1
    Table: Master
    Type: Lookup
    Roll: 1d3
    1: [@Slave]
    2: [@Slave]
    3: {DM==5}[#{1d7} Slave]
    Table: Slave
    Type: Lookup
    Roll: 1d12
    1: a
    2: b
    3: c
    4: d
    5: e
    6: f
    7: g
    8: h
    9: i
    10: j
    11: k
    12: l

    If DM is some kind of limiting variable, with its value set elsewhere in the code, then this also works:

    3: [#{1d{12-DM}} Slave]

    Here, its possible for some other routine or user input to set DM as the die roll reduction value. For example, if DM is a 5 point die roll reduction, but even distribution is desirable (not an excess chance of rolling a 1), then [#{1d{12-DM}} Slave] would be the same as [#{1d7} Slave]. But, if the deduction were set to 3, then #{1d{12-DM}} Slave] would have the effect of rolling a 1 - 9 with equal chance of each number, same as [#{1d9} Slave].

    Hope this helps.

  • Thank you both for your help. Much appreciated.

  • @MrCrumbly , If you still have the slave gen could I have a copy to edit for a storyline?

Leave a Comment