PDA

View Full Version : Story Templates not Generating Unique Values



LordEntrails
February 15th, 2025, 19:58
So I've got a Story template that is trying to make multiple calls to a table, but each time FG returns the same result from the table. The key is that I'm using a callout to an internal reference https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996640973/Using+Story+Templates+to+Create+Random+Stories#Cal lout-Internal-Referencing-%5B%3Ca%3E%5D

i.e. the template calls out a table (Primary Star Class). One of the columns of the first table has a letter in column one (star class). Then there are additional tables (Zone Population x) with the various star class values for x. The intent is that the story should call upon the same zone population table multiple times to get unique values off that table. But, it doesn't do that, each value is the same. And this is repeatable with multiple stories being generated and multiple story templates being used.

Example;
63450

tjlee
February 16th, 2025, 01:59
I'm able to reproduce using the CoreRPG Story Template engine: 63454

Shameless Plug: My Story Template Enhanced (extension) (https://forge.fantasygrounds.com/shop/items/1870/view) works as expected: 63455

I know why too - the CoreRPG template evaluation performs a global substitution on all matches of the expression under evaluation, so when it evaluates the first [Zone Population #Primary Star Class|1#] table callout, it replaces all of the same expression with the same value. Not an easy fix without rewriting the parser like I've already done.

A potential work-around is to do something like [2x][Zone Population #Primary Start Class|1#] which tells the story template to roll twice against the table.
However, CoreRPG doesn't honor the [2x] in this case (didn't investigate why) while my extension does with the results appearing concatenated all on one line: 63457

With my extension, you can modify the story template or table data so that [2x][...] works as expected and the output is on separate lines - more than one way to to solve the problem.

Here's a potential work-around, but as you can see, CoreRPG still does the unexpected while my extension produces expected results: 63458

I put the [Zone Population #Primary Star Class|1#] in a new table named Formatted Population and use the [2x] multiple roll directive in the template to call it twice. I've embedded the line item HTML tags surrounding the table callout <li>...</li>, hence the bullet points in the resulting output. We see in the CoreRPG evaluation of the template, it honors the [2x] directive but repeats the same value while my extension once again produces expected results.

An unsavory work around that works for CoreRPG would be to replicate the [Zone Population X] tables by giving them unique names like [Zone Population X 2], [Zone Population X 3] and then for each time you want to get different results in the story template, you add a line that calls a different version of the same table like so:

[Zone Population #Primary Star Class|1#]
[Zone Population #Primary Star Class|1# 2]
[Zone Population #Primary Star Class|2# 3]
etc.

Since the template expressions are different, they won't get replaced with the same values (unless they coincidentally roll the same values).

LordEntrails
February 16th, 2025, 03:22
Thanks TJ :) I appreciate you looking at this and diving in so deep. Since these tables will be for an official conversion I'm trying to use core functions to get as close as I can. I was wondering if the custom name callouts (:a:b) or the internal callout internal rolling [:[a] [b]:c] might provide a work around. But since I don't understand those yet, (lol) I haven't gotten there yet.

Doug, Moon or Carl, any thoughts if this is some behavior you might look to change/update/fix?

Jiminimonka
February 16th, 2025, 11:15
Much as I would love to use your extension tjlee I am using Story Templates in products for the Store, so I can't use an extension. If your system is less of a mind bender (Lord Entrails seems to think it is) than the current implementation (which is very powerful but requires a lot of though to get your head into) maybe Smiteworks should incorporate your extension into FG and make our lives easier.

Marmus
February 16th, 2025, 14:42
So I've got a Story template that is trying to make multiple calls to a table, but each time FG returns the same result from the table. The key is that I'm using a callout to an internal reference https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996640973/Using+Story+Templates+to+Create+Random+Stories#Cal lout-Internal-Referencing-%5B%3Ca%3E%5D

i.e. the template calls out a table (Primary Star Class). One of the columns of the first table has a letter in column one (star class). Then there are additional tables (Zone Population x) with the various star class values for x. The intent is that the story should call upon the same zone population table multiple times to get unique values off that table. But, it doesn't do that, each value is the same. And this is repeatable with multiple stories being generated and multiple story templates being used.

Example;
63450

I got this way to work...is this what you are looking for?

For your "ST Test" template:


[Primary Star Class]

[:Zone Population #Primary Star Class|1#:Object1]

[:Zone Population #Primary Star Class|1#:Object2]


See result in image:
63464

"Object1" and "Object2" can be any unique name you want.

EDIT:
To add to the above, using the : commands also holds the rolled value to that name for use on the generated story.
For example:


[Primary Star Class]

Roll 1 - [:Zone Population #Primary Star Class|1#:Object1]

Roll 2 - [:Zone Population #Primary Star Class|1#:Object2]

This will also hold the value rolled so that you can use it elsewhere in the Generated Story, as any times as you want.

Roll 1 result again = <Object1>

Roll 2 result again = <Object2>

<Object1>

<Object1>



<Object2>

<Object2>

See result in image:
63466

tjlee
February 16th, 2025, 18:15
Yes, that’s the work around LordEntrails is looking for.

The assignment to store into Object1 and Object2 makes the expressions different so they get evaluated separately.

LordEntrails
February 16th, 2025, 19:12
Thank you Marmus! Really appreciate you figuring this out for me. Will post the final once I get it updated :)

LordEntrails
February 16th, 2025, 19:59
Here's what it looks like for those who want to see what I was hoping to get to.

Now to see if I can get FG to multiply two numbers together to populate the Stellar mass value. And after that to see how I want to handle generating the orbital distances from a range of AU's based upon the Star's Stellar Mass.
63469

LordEntrails
February 17th, 2025, 01:03
Well, this is as far as I got. I think I will be happy with it unless someone has some more ideas.
63473

The part I don't think can be done with core is to use the results from one of the columns of the first table and use it to populate the call of the second table and return just a specific column from that second table. I can get the column call from the first table to define the name of the second table, but as soon as you try to call a column from the second table which is defined with the previous colum result, FG doesn't return anything. See the couple of example/tries below.
63474

If anyone has an idea on that, much appreciated, othersie I will just do some manual reformatting once the results from the first image are done.

Jiminimonka
February 17th, 2025, 10:24
Well, this is as far as I got. I think I will be happy with it unless someone has some more ideas.
63473

The part I don't think can be done with core is to use the results from one of the columns of the first table and use it to populate the call of the second table and return just a specific column from that second table. I can get the column call from the first table to define the name of the second table, but as soon as you try to call a column from the second table which is defined with the previous colum result, FG doesn't return anything. See the couple of example/tries below.
63474

If anyone has an idea on that, much appreciated, othersie I will just do some manual reformatting once the results from the first image are done.

You lost me at "the part I don't think.can be done"... 🤣 :)

LordEntrails
February 17th, 2025, 15:47
You lost me at "the part I don't think.can be done"... 藍 :)
lol yea, well a lot of what I've done is trial and error to see what might work etc. I find the wiki article hard to follow and I don't learn well from videos. But Marmas and TJ certainly seem like they don't have my short comings on this topic so :) Besides, If I document here what I learn maybe it will be useful to others.

Those it may already be obvious to others, I did some other fun little things with the story templates that I will share as well. This here is taking results from the rolled tables and performing math on it and having FG give results. Some of it works, and some doesn't. Specifically the second equation for Diameter doesn't work. Haven't figured this one out yet either, would love some suggestions :)

63480

Works: [:2d10/10:diam]

Does not Work:
[: (1d100+40)/70:diamTwo]
[:1d100+100:diamThree]
[: (1d100+100):diamThree]
[:[1d100+100]:diamThree]

(where ": (" has extra space removed, forum changes it to sad face)

Nylanfs
February 17th, 2025, 18:34
Does not Work:
[: (1d100+40)/70:diamTwo]
[:1d100+100:diamThree]
[: (1d100+100):diamThree]
[:[1d100+100]:diamThree]

(where ": (" has extra space removed, forum changes it to sad face)

For Forums using [ code ] shouldn't sub emojis.



[:(1d100+40)/70:diamTwo]
[:1d100+100:diamThree]
[:(1d100+100):diamThree]
[:[1d100+100]:diamThree]

tjlee
February 18th, 2025, 13:29
According to the CoreRPG documentation, the following works as expected:

[:?1d10:value]
[<value>/2]
As we see, the template evaluates as expected:

2.5
However, this:

[:?1d10+40:value]
[<value>/2]
Results in:

:?1d10+3:value <-- should not appear
6.5
In the above, it performs the assignment to value as expected but the ? hide directive doesn't have an effect.

These expressions don't quite work as expected either:

[:?1d10+3:value]
<value> <--- only line that works properly
[:<value>/2:divide]
<divide>
[:<value>+3:add]
<add>
Results:


:?1d10+3:value <-- should not appear
10 <-- from <value>
:10/2:divide <-- should evaluate and assign to divide
<divide> <-- this shows up because it wasn't assigned
:10+3:add <-- should evaluate and assign to add
<add> <-- this shows up because it wasn't assigned

Testing against my extension produces expected results:


10 <-- from <value>
5 <-- from [:<value>/2:divide]
5 <-- from <divide>
13 <-- from [:<value+3:add]
13 <-- from <add>
I should note that the math calculations are delegated to CoreRPG DiceManager.evalDiceMathExpression(sDiceExpr)


[(10+3)/4/2]
Evaluates to unexpected result: (seems to multiply by 2 instead of divide by 2 - (10+3) = 13, 13/4 = 3.25, 3.25/2 = 1.625, 3.25*2 = 6.5)

6.5
But if you include additional parentheses, it computes correctly:

[((10+3)/4)/2]
Evaluates to:

1.625