Text Processor - Centered Text

Forgive me if this already exists, or if someone else has done it, but I was looking at the text processor commands and this page
http://docs.textadventures.co.uk/quest/text_processor.html
The very bottom of the page caught my eye, and I then came up with this, pasting it into the Start script

game.textprocessorcommands = game.textprocessorcommands
scr => {
  s = Mid(section, 3)
  game.textprocessorcommandresult = "<div style=\"text-align:center\">" + s + "</div>"
}
dictionary add (game.textprocessorcommands, "c", scr)

So now

{c:This prints in the center of the screen.}

But, I thought I'd have a go at adding it to the Text Processor command itself
created the function

<function name="ProcessTextCommand_C" parameters="section, data" type="string"><![CDATA[
    s = Mid(section, 3)
    return (ProcessTextSection("<div style=\"text-align:center\">" + s + "</div>",data))
  ]]></function>

But it's not working.
I know I'm missing a step.


You still need to add it to game.textprocessorcommands. Just that your code will be a little simpler:

game.textprocessorcommands = game.textprocessorcommands
scr => {
  game.textprocessorcommandresult = ProcessTextCommand_C (section, data)
}
dictionary add (game.textprocessorcommands, "c:", scr)

Or edit the dictionary on the <game> element directly, if that's easier.

Also, for speed, it's probably best to only call ProcessTextSection on the part that might contain text processor directives. So you'd be returning "<div style=\"text-align:center\">" + ProcessTextSection(s, data) + "</div>". (Probably a tiny difference here; but a good habit to get into for when you're doing more complex stuff)


OK. Thanks mrangel. I'll check that out.


Log in to post a reply.

Support

Forums