Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How do you regex an entire page before it outputs to reader? [Sugarcube 2.1]

edited April 2017 in Help! with 2.0
Hi. Thanks for all your help.

I've been writing stuff using a lot of twinescript and I just realised I need to run a regex at the end to clean up some grammar mistakes.

Is the text printed into Twinescript saved to a variable somewhere before it's output to the page? I could just regex that in javascript. Alternatively, is there a way to make a replace function fire on the entire passage or an entire element right before it becomes visible to the reader using TwineScript somehow?

TLDR: This is basically my problem. How do I fix it without changing anything inside the print macro?
<<print "I want to edit this text so that an big elephant becomes a big elephant">>

Comments

  • I've been writing stuff using a lot of twinescript and I just realised I need to run a regex at the end to clean up some grammar mistakes.

    Is there a reason you can't do this in the passage editor? What you're proposing seems like using a sledgehammer to do a scalpel's job is all. Why isn't just altering the test in the editor an option?
  • Because the text is randomly generated. But I randomly generated it with TwineScript, not JavaScript. So I don't know how to refer to the variable it's all saved to like I would if I'd done it in JavaScript.
  • First. There is no SugarCube v2.1 at this point in time, so the thread title is incorrect. You might want to work on that in the future.


    At first blush, what you're asking for is nonsensical. If what you want to change are mistakes in the original source, then you should correct them there, before you compile the project. Elsewise, if you simply want some dynamism in your content, then you already have the power to use variables and macros within your markup.

    That said. I get the feeling that you're not explaining your situation very well and this situation is less crazy than it sounds.

    Puppeteer wrote: »
    Because the text is randomly generated. But I randomly generated it with TwineScript, not JavaScript. So I don't know how to refer to the variable it's all saved to like I would if I'd done it in JavaScript.
    If you're randomly generating some text, then either generate it correctly in the first place or store it within a variable as you generate it, so that you may correct it before you output it. The former would, obviously, be the best thing to do, though the latter is workable at least.

    Without some detailed examples of how you're dynamically generating the text in question, it's difficult to offer advice on how to best address your situation.
Sign In or Register to comment.