Silly backdrop scope script
mrangel
18 Dec 2018, 08:27This idea's been bouncing around in my head for a while now. Thought I'd try typing it out.
dummy_scenery_object.parent = player.parent
words = Split ("room;floor;sky;walls;ceiling;feet;hands")
if (HasString (player.parent, "alias")) {
foreach (word, RegexSplit ("\\W+", LCase(player.parent.alias))) {
list add (words, word)
}
}
if (HasString (player.parent, "description")) {
foreach (word, RegexSplit ("\\W+", LCase(player.parent.description))) {
list add (words, word)
}
}
skipwords = Split ("a;the")
foreach (item, items) {
alias = GetDisplayAlias (item)
if (HasAttribute (item, "alt")) {
alias = alias + " " + Join (item.alt, " ")
}
alias = LCase (Trim (alias))
foreach (word, Split (alias, " ")) {
while (LengthOf (word) > 0 and not ListContains (skipwords, word)) {
list add (skipwords, word)
}
}
}
words = ListExclude (words, skipwords)
dummy_scenery_object.alt = Split (Join (words, " "))
if (ListContains (items, dummy_scenery_object)) {
list remove (items, dummy_scenery_object)
}
The dummy scenery object could have a description like "That doesn't seem very interesting", or "You don't want to waste time with that". So that it catches the player trying to interact with objects that are mentioned in the room description but aren't an object's alias.
The object is never in scope, to minimise its disambiguation menus, but it's always visible. It should have an alias like "background" or similar, just in case it shows up somehow.
Oh, I used this function because I couldn't find mention of one in the Quest documentation. Maybe I missed it.
<function name="RegexSplit" parameters="pattern, string" type="stringdictionary"><![CDATA[
words = NewStringDictionary()
pattern = pattern + "(?<!.)"
while (not string = "" and IsRegexMatch (pattern, string)) {
parts = Populate ("^(?<split_left>.*?)"+pattern+"(?<split_right>.*)$", string)
string = DictionaryItem (parts, "split_right")
list add (words, DictionaryItem (parts, "split_left"))
}
if (LengthOf (string) > 0) {
list add (words, string)
}
return (words)
]]></function>

K.V.
18 Dec 2018, 13:37Nice!

Dcoder
18 Dec 2018, 16:14DavyB should see this!
The Pixie
18 Dec 2018, 17:28I am experimenting with a JavaScript version of Quest, and have added a similar object - though you can tag words in the room description to have them as aliases of the background object.

DavyB
19 Dec 2018, 13:04Okay mrangle, this looks very interesting and I'd like to try it out...so I create a dummy_scenery_object somewhere out of the way and put the above code into the start script, with the function in the usual place?
Tried that and Quest complains about invalid XML associated with the function...something about "name cannot begin with '.'" Don't understand enough to sort this out.
mrangel
19 Dec 2018, 19:55put the above code into the start script
No, it was supposed to go in the backdrop scope script.
Quest complains about invalid XML
Oh, I forgot the CDATA tags. I'll fix that now.

DavyB
22 Dec 2018, 16:47Sorry mrangle, there is still a problem with the code. I put it into an empty game, providing simple text for the room description. The result is:
You are in an empty room. The floor, the walls, and the ceiling are all white.
Error running script: Error evaluating expression 'not (string = "") and IsRegexMatch (pattern, string)': parsing "\W+(?<.)" - Invalid group name: Group names must begin with a word character.
Error running script: Cannot foreach over '' as it is not a list
Error running script: Error evaluating expression 'not (string = "") and IsRegexMatch (pattern, string)': parsing "\W+(?<.)" - Invalid group name: Group names must begin with a word character.
Error running script: Cannot foreach over '' as it is not a list"
mrangel
22 Dec 2018, 17:12Typo fix'd. "(?<.)"
should be "(?<!.)"
(which matches "not the beginning of the string" - not relevant in this case, but a general RegexSplit function needs to avoid going into an infinite loop if you pass it a pattern which can match the empty string).
In this case, the expression I'm passing it is "\\W+"
, which matches one or more characters of space or punctuation, giving us an easy way to break the description into words

DavyB
22 Dec 2018, 19:32Error message has changed to:
You are in an empty room. The floor, the walls, and the ceiling are all white.
Error running script: Unrecognised list type
Error running script: Cannot foreach over '' as it is not a list
Error running script: Unrecognised list type
Error running script: Cannot foreach over '' as it is not a list