Tinderbox Forum

Automatic string manipulation/parsing

I am using Tinderbox to organize my data around a tabletop RPG I am running for remote friends. One of the games uses a virtual tabletop that requires a specific text format for character sheets. I have an enormous body of character sheets that are more or less consistently formatted.

Is there a way using Tinderbox to parse all or part of these sheets automatically so that they are converted to the needed format? For example a way to make it so when I paste"Acrobatics (+12)" to a note and perform some operation, it changes the text to “Acrobatics +12”. I can for sure manually apply some string manipulation to the text and do it myself, but if I could automate it, then I could ultimately figure out how to convert my existing data into the XML format used by the game. that would allow me to do mass imports of characters rather than copying and pasting section by section. But you gotta start somewhere.

thanks all!

Christopher Hatty

There’s quite a lot of support in Tinderbox for taking semi-structured text like

Acrobatics: 12
Aeronautic Engineering: 6

and extracting things to attributes like $Acrobatics. Once done, it’s then easy to write agents for things like “All characters who have good acrobatics and know how to repair an ornithopter." And it’s easy to write export templates for the XML.

For simple formats, you’ll want to check out [String].following(), which is limited but very easy to use. For more complex situations, consider regular expressions and [String].contains().

This is a complete list of available actions. Hopefully it may give you some ideas.

Export to XML is definitely possible, I’ve done it in the past.

thanks all. I am hoping to dig into this this weekend. I will post follow up questions here unless you think a new thread is appropriate!

1 Like

what might be useful is to see a sample of the source data you’re passing to Tinderbox and to understand how you are getting it into Tinderbox. Rather than paste big bits of text and then play regex games to find things, consider tab-delim/CSV input allowing you to map data directly to Tinderbox attributes.

For instance, if you made a table in the source app and had a column ‘Acrobatics’, then you could make a Number-type user attribute Acrobatics and each row would store the Acrobatics column value as that notes’ $Acrobatics. In the example you give, the value would be 12 but it could be -0.05 or such.

To see a note’s $Acrobatics, you’d add the ‘Acrobatics’ attribute as a Displayed Attribute for the notes.

If the above appeals, don’t worry about doing it all right the first try. start with one or two columns and data of a few different types (numbers, text, lists boolean (true/false), etc.) and build out from that.

With a little experimentation you can circumvent the painful process of having everything in a note’s text ($Text) and having to excavate it with regex. There are lots of neat action code operators like the ones already suggested in 2Eastgate’s answer (only some using regex).

Good luck and do come back with questions. Fine to start here, but if you’ve a number of discrete questions it can be helpful (especially for later readers) if we explore them in separate trhreads with explanatory titles.