I think the online authors deserve a text processor command that wraps a string with <
>
.
My original thought was to add a "{br}"
for "<br/>"
, but it seems like it would be almost the same amount of work to have "{element:br/}"
print <br/>
, or "{element:style}"
print <style>
, or what have you.
Would this be handy to have in the web editor?
(At the moment it doesn't matter, because I can't find where I once read how to add text processor commands, but I'll eventually find it. Or someone will hit me with a link or something.)
Doh! It was my post I was almost remembering.
https://textadventures.co.uk/forum/quest/topic/qfu6jgz52u6pteocerjavw/text-processor-adding-br-hr-etc
Hmm… That {element:
command sounds like a good idea (at least for the online editor, where strings containing <
break code view). But I think it might get tiresome typing element
so many times; maybe a shorter synonym would be a good idea. Even something like {:style}
.
Off the top of my head, maybe you could do something like (edited)…
textprocessordefault => {
if (IsRegexMatch(":?/?\\w+\\b((?<=\\s)\\w+\\b|(?<=\\s)\\w+=\\w+\\b|(?<=\\s)\\w+=\"[^\"]*\"|(?<=\\s)\\w+='[^']*')*/?\\s*", section)) {
if (StartsWith (section, ":")) section = LTrim (Mid (section, 2))
game.textprocessorcommandresult = "<" + section + ">"
}
else {
game.textprocessorcommandresult = "@@@open@@@" + ProcessTextSection (section, data) + "@@@close@@@"
}
}
game.textprocessorcommands = game.textprocessorcommands
dictionary add (game.textprocessorcommands, ":", textprocessordefault)
dictionary add (game.textprocessorcommands, "/", textprocessordefault)
Then you can do {:span id="spoooon"}spoon?{/span}
or whatever if you're getting frustrated with the online editor :)
Oh yeah, that looks much better.
I was trying to avoid adding new things to any pull requests this time around, but this would make like much easier for online authors -- and I don't see how it could hurt anything.
Just got around to this.
I used that code, and:
Error running script: Error compiling expression 'IsRegexMatch(":?/?\w+\\b((?<=\\s)\\w+\\b|(?<=\\s)\\w+=\\w+\\b|(?<=\\s)\\w+=\"[^\"]*\"|(?<=\\s)\\w+='[^']*')*/?\\s*", section)': SyntaxError: Unexpected character: "Line: 1, Column: 14
Error running script: Error compiling expression 'IsRegexMatch(":?/?\w+\\b((?<=\\s)\\w+\\b|(?<=\\s)\\w+=\\w+\\b|(?<=\\s)\\w+=\"[^\"]*\"|(?<=\\s)\\w+='[^']*')*/?\\s*", section)': SyntaxError: Unexpected character: "Line: 1, Column: 14
{:b}Hello{:/b} world.
I'm betting it's just a minor typo, but I can't figure it out. (I need to learn RegEx.)
I tried it on RegExr, and it said it had unescaped /
When I escaped those, it still didn't like me.
I did, however, seem to get it working with @@@lt@@@
for <
. Typing @@@lt@@@
sucks, though. :)
Tested and debugged. Like every time I try writing long regexes off the top of my head, there's a missing \
. In this case, it was \w
instead of \\w
the first time. (One backslash for Quest's string processing, one for the regex engine)
I tried it on RegExr, and it said it had unescaped
/
When I escaped those, it still didn't like me.
It was actually an unescaped \
. The reason it probably complains about the /
is because many languages (inspired by Perl) use /
as an alternate quote character for surrounding regexes; which doesn't apply in Quest.
Tips for debugging this stuff: It says the error is at character 14, which I believe is the opening quote, and the error message isn't regex specific. So search the string for its backslashes, and make sure they're all escaping a \
or a "
. Any stray \w
or \S
or whatever needs to be passed to the regex engine, so the slash should be doubled to keep the Quest interpreter trying to do stuff with it.
Thank you!
Like every time I try writing long regexes off the top of my head, there's a missing
\
.
You, sir, are a wealth of knowledge. I knew it was just something trivial like that. I didn't add it to a game or anything like that. :)
Tips for debugging this stuff
Oh, I see! I just learned (at least) two things from that.
Thanks again! I'm about to add this to the changes for the upcoming Quest release. This will be a great addition for online authors.
To be honest, for stuff like this it would probably be easier to put the regex in a string attribute; so that you don't have to worry about what it looks like escaped to work with the "
operator. But of course I can't do that online :p
Although I could have a dummy game on my account with a blank msg
line; paste the correct regex in and then change the type from "Message" to "Expression" to get a quoted string. Not 100% sure, but I suspect that the editor will escape characters when you do that, won't it?
Okay, so, to be sure (because I'm not, haha), to add this to the Core libraries:
WorldModel\WorldModel\CoreTypes.aslx
Add this to game.textprocessorcommands
:
<item key=":">
game.textprocessorcommandresult = ProcessTextCommand_Element (section, data)
</item>
<item key="/">
game.textprocessorcommandresult = ProcessTextCommand_Element (section, data)
</item>
WorldModel\WorldModel\CoreOutput.aslx
Add this function:
<function name="ProcessTextCommand_Element" type="string" parameters="section, data"><![CDATA[
if (IsRegexMatch(":?/?\\w+\\b((?<=\\s)\\w+\\b|(?<=\\s)\\w+=\\w+\\b|(?<=\\s)\\w+=\"[^\"]*\"|(?<=\\s)\\w+='[^']*')*/?\\s*", section)) {
if (StartsWith (section, ":")) section = LTrim (Mid (section, 2))
return ("<" + section + ">")
}
else {
return ("@@@open@@@" + ProcessTextSection (section, data) + "@@@close@@@")
}
]]></function>
This works when I test it, but I tend to overlook changes that might effect other functions.
Groovy! I added those changes, and everything seems to be working smoothly.
You will be an unsung hero. Everyone who creates Quest games online will unknowingly be in your debt. :)
https://textadventures.co.uk/forum/site/topic/oylj_u9vquwpqzv6itgnya/moving-the-forums-to-github-discussions
How do you feel about switching from the forums to GitHub Discussions, mrangel?
Do you think you'd be active there like you are here?
To be honest, for stuff like this it would probably be easier to put the regex in a string attribute; so that you don't have to worry about what it looks like escaped to work with the " operator. But of course I can't do that online :p
I added these changes, and I also modified things so there is a game attribute tab in the online editor.
If you want to check it out: http://quest-test.textadventures.co.uk/Edit/Game/1
It is set up for debugging; so, it only loads that one game, but it does save the changes.
Also, the play button won't work from the editor. You can, however, use this link to play the game file: http://play-test.textadventures.co.uk/Play.aspx?id=editorgame&file=h:\root\home\kvqueststuff-001\www\WebEditor\EditorGames\c8b531c8-d071-482b-a41b-578a4f657a9d\WebEditorTester.aslx