Adding a key to a script dictionary in a text adventure

W.H. Dunnlatch
10 Jul 2017, 17:52Hello,
I'm fairly certain I'm overlooking something simple, but I've been through the documentation and the forum with no results (or I overlooked something there, too), so:
How do I add a key to a script dictionary upon entering a certain room?
I don't want the NPC to respond to a certain topic until the player has played through the scene concerning the topic.
(Or am I better off just writing an IF...THEN.. script for the topic, with the reply "There is no reply." if the room hasn't been visited? I could do that, but I'd rather learn how to add the key.)
I made a sample game that should provide any information anyone may need to help me out. (If you play the game, the room description of the second room will explain what I'd like to do, as well.)
Thanks in advance!
Here's the sample:
<!--Saved by Quest 5.7.6386.17178-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Ask Ralph About Things">
<gameid>e15effd8-9449-4ec7-a1f3-a07e2f9e9c84</gameid>
<version>1.0</version>
<firstpublished>2017</firstpublished>
<author>W.H. Dunnlatch</author>
<subtitle>A study in adding keys (with msg scripts) to ASK...ABOUT... lists</subtitle>
<feature_asktell />
</game>
<object name="room">
<inherit name="editor_room" />
<description>Go into the next room.</description>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="Ralph">
<inherit name="editor_object" />
<inherit name="namedmale" />
<look><![CDATA[Ralph the penguin is a character I borrow from a friend of mine who writes his 'real' stories.<br/>(Enter {command:CLOSELY EXAMINE RP} for more!)]]></look>
<displayverbs type="stringlist">
<value>Look at</value>
<value>Speak to</value>
<value>Closely examine</value>
</displayverbs>
<topics type="stringlist">
<value>topic1</value>
<value>topic2</value>
</topics>
<speak type="script">
game.askaboutobject = Ralph
ShowMenu ("What you like to ask Ralph about?", Ralph.topics, true) {
if (not result = null) {
DoAskTell (game.askaboutobject, result, "ask", "askdefault", "DefaultAsk")
}
}
</speak>
<closelyexamine type="script"><![CDATA[
msg ("<div id=\"bio\"><br/><center><h3 style='font-family:Georgia !important;text-shadow:-1px -1 px 1px black !important;'>Ralph the penguin</h3></center>Ralph is not really from around here, but he is very closely related to the Emperor penguin.<br/><br/>Tidbits concerning Ralph:<br/><ul><br/> <li style=\"font-family:Georgia !important\">Ralph is actually a character I borrow from an author friend of mine.</li><br/> <li style=\"font-family:Georgia !important\">Ralph has a thing for dodos.</li><br/> <li style=\"font-family:Georgia !important\">If you give Ralph the laser sword, he will attack antagonists on command.</li></div>")
wait {
SetFontSize (14)
ShowRoomDescription
}
]]></closelyexamine>
<ask type="scriptdictionary">
<item key="topic1">
msg ("This is the reply to topic1.")
</item>
<item key="topic2">
msg ("This is the reply to topic2.")
</item>
</ask>
</object>
<exit alias="in" to="certain room">
<inherit name="indirection" />
</exit>
</object>
<verb>
<property>closelyexamine</property>
<pattern>closely examine</pattern>
<defaultexpression>"You can't closely examine " + object.article + "."</defaultexpression>
</verb>
<object name="certain room">
<inherit name="editor_room" />
<description><![CDATA[<br/><h1>What happens and what I'd like to happen upon entering this room (behind the scenes):</h1><ul><li>The string "Harbinger" is added to Ralph.topics, so it will display as a selection when you TALK/SPEAK TO RALPH.<br/>(I have this working perfectly already in the main game. This game is just a sample to post on the forum.)</li><br/><li>THIS IS THE ONE I NEED HELP WITH: I want it to add a key to ASK RALPH ABOUT: <code>The Harbinger, Print "\"He says we're DOOMED!\" replies Ralph, doing his best to mimick the harbinger."</code></li>]]></description>
<beforeenter type="script"><![CDATA[
msg ("<b>NOTE: I want to add a script that adds a key to Ralph's ASK...ABOUT... list when the player enters this room the first time.</b>")
list add (Ralph.topics, "topic3 (added upon entering a certain room but needs to be added to Ralph.ask)")
]]></beforeenter>
<exit alias="out" to="room">
<inherit name="outdirection" />
</exit>
<object name="The Harbinger">
<inherit name="editor_object" />
<inherit name="namedmale" />
</object>
</object>
<turnscript name="rp_follows">
<enabled />
<script>
MoveObjectHere (Ralph)
</script>
</turnscript>
</asl>
The Pixie
10 Jul 2017, 21:29Try this:
script => {
msg("Harbinger is just this guy, you know?")
}
dictionary add(Ralph.ask, "harbinger", script)
I can never remember if the arrow thing goes =>
or <=
, or flip it if that does not work.

W.H. Dunnlatch
10 Jul 2017, 22:56@The Pixie,
You rock!
(Nice Hitchhiker's reference, by the way! When I tested the code out, I thought, "I don't remember putting that response in THIS game!" (Although, I did put it in the last game when you asked Ralph about his author.))
Thanks!