Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

That absolutely does, thank you! I realize though that I could have done a better job providing context. I'm migrating a project that generates content for a tabletop RPG from something I built in Twine to Decker. A lot of random[] functions.

For a lot of the cards I'm working on, there's a contextual link between them that's based around a single word. In the below case, the word "Alien" in the Anecdote field would ideally be hyperlinked to a card titled Aliens, which would have a similar list of fields with randomly selected values in fields. I initially tried including link[aliens] in the array, but that just caused the aliens card to load upon clicking the button that contained the array.

These results are never a composite of multiple results, but just a fixed list of potential results, just in some cases there's a "contextual link" to another card. So as far as the solutions you provided, I could have "link fields" that contain the few instances of when a link makes sense within the card and just use *.text as the array value in those cases, right?  I'm willing to do this programmatically if it'll be a cleaner solution, though. Thank you again!

(+2)

Just to make sure you're clear on the distinction, a field's .value attribute is a table, and a field's .text attribute is a string:

An rtext table can contain hyperlinks, inline images, and multiple fonts, but a plain string cannot. In many situations that ask for an rtext table you can supply a string and it will be "widened" into rtext, but it will all be in the default font. If you copy the .value of one rich text field to another it will preserve its formatting, but if you copy the .text you will flatten it out into a plain text representation.

(For anyone with web development experience, field.value versus field.text is loosely similar to element.innerHTML versus element.innerText.)

Decker 1.34 introduced a new "rtext.replace[]" utility function that might be handy. If you're working with a lot of text, links, and cards, it might be useful to write a deck-level utility function that finds certain keywords in a string or rtext table and replaces them with appropriate links, which you could then call whenever you populate a field. For example, perhaps something like this:

on contextualize text do
  db:insert keyword replacement with
   "Alien"  rtext.make["Alien"  "" "About Aliens"     ]
   "Weapon" rtext.make["Weapon" "" "Weaponry"         ]
   "Snacks" rtext.make["Snacks" "" "Delicious Treats" ]
   "Zombo"  rtext.make["Zombo"  "" "https://zombo.com"]
  end
  rtext.replace[text db.keyword db.replacement]
end

There's basically no limit to the possible complexity here (for example, you could automatically populate the keyword list by inspecting the titles of cards in the current deck), so it's up to you to choose what makes sense to you and is reasonably convenient for your purposes.

(+1)

First off I really appreciate your time in providing practical solutions. I gave this my best shot before returning here but every attempt I made at implementing the utility function you provided, at either the deck level down to the control itself, did not seem to work. I could get it to work within the Listener, but any table expressions seemed to do nothing outside of Listener. I'm sure I'm missing something, but I couldn't find a solution or workaround. 

(+1)

Are you writing the result into a widget?

If you had a rich text field named "foo" which contained some of the words defined in the table for contextualize[], you'd apply it to the field something like this:

foo.value:contextualize[foo.value]
  • reading "foo.value" produces a rich text table.
  • "contextualize[foo.value] " calls the contextualize function with that rich text table and returns a modified rich text table.
  • the colon (:) is the assignment operator in Lil.
(+1)

As I anticipated, my issue was a syntax one and I wasn't properly calling "contextualize". I also unnecessarily added a comma delimiter to each of the rtext.make[] functions (I use Power Apps and JSON a lot with work). Everything is working as intended now, thank you!