Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Looking for help with Scriptcards and Rollable Tables

June 19 (2 years ago)

Edited June 19 (2 years ago)

Am trying to use scriptcards with rollable tables that use inline rolls. From what I understand it seems like what I'm wanting to do isn't possible but would like to see if anyone has any ideas. The code below works fine but when it outputs the table text it doesn't use the dice rolls associated with the names in the table.


As an example the grassland table looks like this

[[1d4]] plant 1

[[1d4]] plant 2

[[2d4]] plant 3

[[1d4]] plant 4

[[1t[CommonPlantsTable]]]

[[1d4]] plant 5

[[2d4]] plant 6

[[1d4]] plant 7

[[1d4]] plant 8


Currently everything works with recursive tables with this macro.

?{Choose Terrain|

Grassland,!rt You find [[ 1t[Grassland] ]]! |

Forest,!rt You find [[ 1t[Forest] ]]! |

Peak,!rt You find [[ 1t[Peak] ]]! |

Desert,!rt You find [[ 1t[Desert] ]]! |

Jungle,!rt You find [[ 1t[Jungle] ]]! |

Hill,!rt You find [[ 1t[Hill] ]]! |

Mountain,!rt You find [[ 1t[Mountain] ]]! |

Swamp,!rt You find [[ 1t[Swamp] ]]! |

Underdark,!rt You find [[ 1t[Underdark] ]]! }


Really at the end of the day it doesn't matter because it works fine, I was just wanting to make it look nice with scriptcards by changing the color of the background to  correspond with the terrain choice and display a picture of the plant they collect.

Any help would be appreciated.


!script {{

    --#title|Herbalism

    --=GrasslandRoll|[T#Grassland]

    --=ForestRoll|[T#Forest]

    --=HillRoll|[T#Hill]

    --=JungleRoll|[T#Jungle]

    --=DesertRoll|[T#Desert]

    --=MountainRoll|[T#Mountain]

    --=PeakRoll|[T#Peak]

    --=SwampRoll|[T#Swamp]

    --=UnderdarkRoll|[T#Underdark]

    --&Terrain|?{Terrain Type?|Grassland|Forest|Jungle|Hill|Desert|Mountain|Peak|Swamp|Underdark}

    --C[&Terrain]|Grassland:>One;[&Terrain]|Forest:>Two;[&Terrain]|Jungle:>Three;[&Terrain]|Hill:>Four;[&Terrain]|Desert:>Five;[&Terrain]|Mountain:>Six;[&Terrain]|Peak:>Seven;[&Terrain]|Swamp:>Eight;[&Terrain]|Underdark:>Nine;[&Terrain]

    --X|

    --:One|  --+Collect|[$GrasslandRoll.tableEntryText] --<|

    --:Two|  ---+Collect|[$ForestRoll.tableEntryText]   --<|

    --:Three|  --+Collect|[$JungleRoll.tableEntryText]   --<|

    --:Four|  --+Collect|[$HillRoll.tableEntryText]   --<|

    --:Five|  --+Collect|[$DesertRoll.tableEntryText]   --<|

    --:Six|  --+Collect|[$MountainRoll.tableEntryText]   --<|

    --:Seven|  --+Collect|[$PeakRoll.tableEntryText]   --<|

    --:Eight|  --+Collect|[$SwampRoll.tableEntryText]   --<|

    --:Nine|  --+Collect|[$UnderdarkRoll.tableEntryText]   --<|

}}


June 19 (2 years ago)

Edited June 19 (2 years ago)
timmaugh
Forum Champion
API Scripter

Aside from any built-in ScriptCards solution, ZeroFrame can help (and it works within ScriptCards). ZeroFrame has a .value syntax that you can append to any roll (or roll marker -- ie, $[[0]] ) to extract the value... which ZeroFrame will then continue to expand.

For instance, if you wanted an entry from your Grasslands table (and you wanted to also roll the roll that is contained there), you could do this:

[[1t[Grassland]]].value

To see that in chat, you can just use ZeroFrame's {&simple} tag and start the command like a script command:

![[1t[Grassland]]].value {&simple}

One entry in the grasslands table is another roll against a different rollable table, so you would want that entry in the grasslands table to also have a .value attached to it:

[[1t[CommonPlantsTable]]].value

That way, when this item comes up, the next roll will be extracted, too.

ZeroFrame will work before ScriptCards gets the message, so you can't use ScriptCards syntax to control ZeroFrame behavior -- you have to do the opposite. In other words, what you get from ZeroFrame will be what is in your command line (and a part of the message) when ScriptCards sees it. The good news is that you can use the same queries that you have in the ScriptCards example to drive the table you'd pick from... you just have to delay Roll20 recognizing the roll (because rolls typically resolve before queries). Here's how that would generally look (not proficient in ScriptCards syntax, so these are just the steps you have to take):

1) Somewhere you will have this query... it can be assigned to a variable, or, if you don't need it elsewhere (which you might not after you get the value using ZeroFrame), it can exist only in the ZeroFrame roll construction:

?{Terrain Type?|Grassland|Forest|Jungle|Hill|Desert|Mountain|Peak|Swamp|Underdark}

2) Your roll against the table now happens in a ZeroFrame construction (delayed roll to let the query resolve; a .value suffix to extract the value):

[\][\]1t[?{Terrain Type?}] \]\].value

If you don't need the query elsewhere, just put the entirety of the query syntax where that shorthand reference is.

Either way, that will be filled with the results of the roll, so this point in your ScriptCards command line will now read something like:

$[[1]] plant 1

...where that roll marker will point to the new inline roll that was a part of the rollable table entry (for plant 1, you had [[1d4]] as the roll in that row).

3) ...

4) Profit

That's it. Once you know you're getting the results from your table back to the ScriptCards command line, it's up to you what you do with it (or need to do with it, to satisfy ScriptCards syntax rules). But doing this should simplify the number of lines you have to use to in ScriptCards, and you can get on to the formatting of the result.

I appreciate the reply, I am confused where to put this all. Does this all go in the !script command for the scriptcard?

I've been trying to use the .value command but it doesn't seem to affect anything when used within the scriptcard. 

When I put [\][\]1t[?{Terrain Type?}] \]\].value into the query of the scriptcard the query stopped working.

I attempted to put this [[1t[CommonPlantsTable]]].value into the table but that doesn't seem to be helping either.

I tried to make a separate Variable form[T#Grassland].value but that just out put the same line as without the .value

June 19 (2 years ago)
timmaugh
Forum Champion
API Scripter

You installed ZeroFrame, correct?

ZeroFrame constructions (like all metascript constructions) go right in the command line of other scripts... or in the text of the message you want to hit the chat panel (using {&simple}).

I think what I forgot is that in order for ZeroFrame to un-defer the inline roll (so that it turns into an actual return from the table, rather than just that string of characters), it needs to be told that a metascript (even itself) has changed the command line. If we don't have that, it figures its work is done.

The easiest way to do that is to define a global variable that does nothing:

{&global ([SomethingThatWillNotOccurNaturally] )

...or you could store the return of the query:

{&global ([TheTerrain] ?{Terrain Type?|Grassland|Forest|Jungle|Hill|Desert|Mountain|Peak|Swamp|Underdark})}

... which can be handy in certain situations.

So, with that said, and to help with the "where do I put this" question... here's a really basic ScriptCard using this functionality:

!script {{ {&global ([TheTerrain] ?{Terrain Type?|Grassland|Forest|Jungle|Hill|Desert|Mountain|Peak|Swamp|Underdark})}
  --#title|Herbalism: TheTerrain Foraging
  --+|You collect [\][\]1t[TheTerrain] \]\].value
}}

And a few examples of the output:


Well that works just fine, thank you so much for the help!!