@TheMadExile Yes, I know you already
could not fathom it, but hear me out.
I'm a lazy bastard who has a list of things I'd like to replace with a styled version.
@aStyle;ADept@@bStyle;BDept@@cStyle;CDept@@>>
}>>
I may add/delete/change the department names and styles of each of them, and I don't want to hunt through all my Passages for each of them. Really, it's just like Harlowe's
replace, instead on a particular String instead of a hook.
So, what's this crazy method you spoke of? Does it use
postrender/predisplay?
Also, is there a better way to define the replaceList array?
Comments
If this is simply about replacing text within your raw passages once in a blue moon, then I suggest using Twine 2's Find and Replace feature.
If this is about having dynamic text at run time, then my answer now remains the same as it was then. Dynamic text is the basic reason why any/all of the following exist: $variables, macros, widgets, etc. If you want dynamic text, look into the usual suspects. For example, using properties on the setup object: Or via widgets: Etc, etc, ad nauseam.
But, alright, I get the point. For further reference, though, can you elaborate on why it's crazy/insane?
Would it introduce hard to debug issues? Or is it something that's just! Isn't! Done!
Like instead of $passage where $passage could be set up with a variable, he wanted some type of system to crawl through the text before is was displayed and use regular expressions to find and replace specific text. Which is about 100000000000000 times the work and processing requirements of just using a variable, for no discernible benefit.
It's reinventing the wheel, not the SugarCube wheel, more like the wheel of computer programming in general. So it's not done because why would it be? It'd be like building a new house in order to make your bed.
I guess the only question remaining is how does Harlowe do it, then? Harlowe's (replace:) macro targets a hook, but it can also target an arbitrary string. Or maybe I'm just looking at it wrong.
For example, a simple text only replacement might work out like the following:
A text and markup replacement:
Otherwise I believe to understand how Harlowe renders a Passage you need to first look at the code for the Section.renderInto() method found in the section.js file which describes what is being done (and when it is done) during the rendering process, I think the call to Utils.findAndFilter() may be of some interest. Then you will need to understand what a ChangerCommand is and how they work.