Nesting [# within [@

Hi all,

Working on my spell scroll table, and I hit an interesting challenge. I have a Lookup table called "magicUserSpells" with 9 indices - one for each spell level, which is itself a sub-table of actual spells:
Table: magicUserSpells
Type: Lookup
Roll: 1d9
1:[@muSpells01&;#93;
2:[@muSpells02&;#93;
3:[@muSpells03&;#93;
4:[@muSpells04&;#93;
5:[@muSpells05&;#93;
6:[@muSpells06&;#93;
7:[@muSpells07&;#93;
8:[@muSpells08&;#93;
9:[@muSpells09&;#93;
# MAGIC SPELL LIST
# -------------------------
Table: muSpells01
Charm Person
Detect Magic
Hold Portal
Light
Magic Missile
Protection from Evil
Read Languages
Read Magic
Shield
Sleep
# -------------------------
Table: muSpells02
...etc...

In my table of random spell scrolls, I'd like results that give me (for example) 2 spells of levels 1-3. I attempted this:
[@2 [#{1d3} magicUserSpells] >> implode]

But IPP throws a Missing Table error. I checked the console, and realised the problem, which actually makes sense:

IPP is first rolling indices 1-3 on the "magicUserSpells" table and coming up with "1:[@muSpells01]";, "2:[@muSpells02]";, or "3:[@muSpells03]";. Let's say it comes up with "1:[@muSpells01]";, so it rolls on that sub-table and comes up with (for example) "Magic Missile". IPP then tries to roll twice on the "Magic Missile" table, which doesn't exist - hence the Missing Table error.

Given that IPP is working as expected, is there another way to accomplish what I'm trying to do? Or is this crazy talk?

Cheers,

Comments

  • Hi esmale,

    You're right, IPP can have problems when doing multiple things (in your case specifying quantity and exact picks) against the same table at the same time. That said, such things can usually be achieved by breaking up the task a bit.

    In this situation, the @2 has to stay, because you want a specific quantity and you want to make use of "implode". To get to the limited-random level, then, we need to create a subtable that can take a parameter (using "with") and use that parameter to when calling your original magicUserSpells.

    My first attempt was this:
    table: start
    [@2 magicUserSpellsByLevel with {1d3} >> implode]
    
    table: magicUserSpellsByLevel
    [#{$1} magicUserSpells]
    
    (missing), (missing)
    (missing), (missing)
    (missing), (missing)

    ...but the problem here was that by the time we got to the last line above, the value of $1 had apparently already been forgotten, and I got the bizarre-looking message "Missing Table: magicUserSpells".

    So, OK, how about this:
    table: start
    [@2 magicUserSpellsByLevel with {1d3} >> implode]
    
    table: magicUserSpellsByLevel
    {x=={$1}}[#{x} magicUserSpells]
    
    Protection from Evil3, Shield3
    Sleep1, Protection from Evil1
    Light2, Read Languages2

    (the numbers at the end of the spell names are there to tell me which list of spells it's choosing from)

    Almost there! Unfortunately, it looks like the original {1d3} roll doesn't change between iterations. So once IPP has rolled, say, a 1 for magicUserSpellsByLevel, we're just going to get level-one spells from there on out.

    The trick then is to shift the rolling into magicUserSpellsByLevel, like this:
    table: start
    [@2 magicUserSpellsByLevel with 1d3 >> implode]
    
    table: magicUserSpellsByLevel
    [#{{$1}} magicUserSpells]
    
    Sleep1, Charm Person3
    Charm Person2, Magic Missile2
    Read Languages3, Charm Person1

    The semi-clever part is the double-interpolation of the $1. First an interpolation to bring out the "1d3" part, and then a second one to actually perform the roll.

    Incidentally, you probably want to change magicUserSpells to use deck picks, so you don't get duplications.
    Table: magicUserSpells
    Type: Lookup
    Roll: 1d9
    1:[!muSpells01]
    2:[!muSpells02]
    3:[!muSpells03]
    4:[!muSpells04]
    5:[!muSpells05]
    6:[!muSpells06]
    7:[!muSpells07]
    8:[!muSpells08]
    9:[!muSpells09]
    

    Hope this helps!
  • Hi largando,

    "Semi-clever"? The hell you say - the double-interpolation of the $1 var is flipping brilliant! I never would have thought of that. You definitely sorted it - thanks a lot!

    I was hoping to avoid the use of an interim table, but I think you're right - sometimes it's easier to break things up. So now I have a table that creates clerical or magical spell scrolls as described in S&W Core - which is precisely what I wanted.

    One piece of weirdness, though:

    I've set up the first part as you showed in your example:
    [@ {$spellbook} with 1d3 >> implode]
    

    This calls the appropriate clerical or magical spell-picker table to select a single 1st- to 3rd-level spell and it works fine. But since it's a single spell, I removed the implode filter:
    [@ {$spellbook} with 1d3]
    

    This throws a '(missing)' error - somehow the {$spellbook} variable is being set and passed, but it gets lost somewhere along the way. If I put the implode filter back, it works fine.

    Odd. Maybe this one's for Ed, or perhaps in your vast IPP mastery you've seen this before.

    PS - I avoided deck picks on the spell tables deliberately, but thanks for the tip.

    Thanks again!

    Cheers,
  • Glad you liked it!

    To answer your other question I might need to see the rest of the code, but offhand I'd guess that your problem is the space between the "@" and the name of the table.

    As far as the deckpicks go, yeah, after I posted I realized that spell scrolls might very well have duplicates. I was thinking of spell books; my bad.

    Sadly, my mastery is far from vast. I just for some reason enjoy stretching the boundaries of what can be done with IPP.
  • I'll do some testing to see if the spacing is the issue, though for now, I'm glad it's working - plus my OCD doesn't mind that I'm applying the implode filter consistently, even for single-entry results ;)

    I'll share out the tables anon - short version is that they're all separate files. The spells table is called by the magic-items table, which in turn is called by the NPC generator (and if you're trying to push the IPP boundaries, you know all about creating external tables for re-use). But for now, suffice to say that there's some more work I want to apply before going public.

    Thanks again! Cheers,

Leave a Comment