0 votes
by (170 points)

Harlowe 2.2.1

I am trying to create a branching dialogue for all NPCs in game, while staying in the same passage. I figured using a datamap would be best, but I was challenged on how to execute a loop. I tried to style my datamap using the cookbook reference by @prof_yaffle but it's one of the few examples without a downloadable sample and the javascript is giving me errors. Specifically: "cannot read property 'create' of undefined".

After banging my head against the wall for days, I just started to create $topics for each characters, and treat them like an inventory system where each new topic would be added to an array. But with a single character it means dozens of passages and hundreds of if: statements. I want to use a datamap but I cannot figure out how to list the items in this array. Do I even need to? Are hundreds of passages going to slow down my player's experience?

Here is the cookbook set-up:

Passage: Startup

(set: $topics to (a: "castle", "smithing", "soldiers"))

(set: $bartender to (dm: "castle", (a: "Ah, lord Appleby rules there", (a: "lord appleby"), ""), "smithing", (a: "My brother is the best smith in the town", (a: "brother"), ""), "soldiers", (a: "They keep the bandits away", (a: "bandits"), ""), "brother", (a: "The best blacksmith in town", (a:), ""), "lord appleby", (a: "He does a fairly good job of ruling", (a:), ""), "bandits", (a: "Used to cause all kinds of trouble for the traders, but the soldiers keep them in check now.", (a: "soldiers", "traders"), ""), "traders", (a: "They come through here every week peddling their wares.", (a:), ""), "end", (a: "Be off with you now. I have a business to run", (a:), ""), "unknown", (a: "I don't know much about that", "You'll have to ask someone else", "Who knows?")))

Passage: bartender

(set: $__conv to $bartender)(set: $__option to "")(set: $__endpassage to "leave_bar")(display: "conversation")

Passage: conversation

{(unless: $__option is "")[
(if: $__conv contains $__option)[
(set: $__response to $__conv's $__option)
(print: $__response's 1st)
(print: $__response's 3rd)
(set: $topics to $topics - $__response's 2nd)
(set: $topics to $__response's 2nd + $topics)](else:)[
(print: (either: ... $__conv's unknown))]]}

You can ask about the following:
(print: conversation.list_options($topics).join(", "))

Or you can (link-repeat: "end the conversation")[
(print: $__conv's end's 1st)
(print: $__conv's end's 3rd)
(display: $__endpassage)]

Passage: leave_bar

[Bye]

Story Javascript:

window.conversation = {}
window.conversation.list_options = function(topics) {
return topics.map(function(topic){ return '(link: "' + topic + '")[(set: $__option to "' + topic + '")(goto: "conversation")]'})
}

While I understand what the code is trying to do, I can't figure out why 

(print: conversation.list_options($topics).join(", "))

is causing the "Cannot read property 'create' of undefined".

Any insight you can offer would be appreciated.

My "work around", not using javascript looks like this (using my variables):

[//Chat with Shannon//]

[]<chatlog|

[<!-- After you've made first contact with Shannon--!>]\
[(set: $shannon_topics to (a: "university", "drug trial", "university", "clinic", "roommates"))
(if: $indorm is 1)[It's weird to be texting in the same room together.]\
(if: $shannon_topics's length > 0)[Ask Shannon About: (print: $shannon_topics.join(", ")).]
(else:)[Having exhausted all topics, you decide to wrap your conversation with Shannon with a yellow hand signing a v.]

(click: "university")[(replace: ?chatlog)[(display: "conv_university")]]
(click: "roommates")[(replace: ?chatlog)[(display: "conv_roommates")]]
(click: "Shannon")[(replace: ?chatlog)[(display: "conv_Shannon")]]
(click: "nursing degree")[(replace: ?chatlog)[(display: "conv_nursingdegree")]]
(click: "dormatory")[(replace: ?chatlog)[(display: "conv_dormatory")]]
(click: "our room")[(replace: ?chatlog)[(display: "conv_ourroom")]]
(click: "drug trial")[(replace: ?chatlog)[(display: "conv_Shannon")]]
(click: "finals")[(replace: ?chatlog)[(display: "conv_drugtrial")]]
(click: "influenza")[(replace: ?chatlog)[(display: "conv_influenza")]]
(click: "waterbottle")[(replace: ?chatlog)[(display: "conv_waterbottle")]]
(click: "computer")[(replace: ?chatlog)[(display: "conv_computer")]]
(click: "virus")[(replace: ?chatlog)[(display: "conv_virus")]]
(click: "food card")[(replace: ?chatlog)[(display: "conv_foodcard")]]
(click: "money")[(replace: ?chatlog)[(display: "conv_money")]]
(click: "computer lab")[(replace: ?chatlog)[(display: "conv_computerlab")]]
(click: "migraines")[(replace: ?chatlog)[(display: "conv_migraines")]]
(click: "virtigo")[(replace: ?chatlog)[(display: "conv_virtigo")]]

[(link-goto: "Return", (history:)'s last)]](ShannonChat|
(if: $drappt is 1 or $indorm is 1)[(show: ?ShannonChat)]
]\

And, rather than using a datamap, I'm just using a bunch of conditional statements for each topic, in the separate passages. Any advice?

 

Cookbook reference: http://twine.analytical-engine.co.uk/Cookbook.html

Chat-like conversations reference: https://twinery.org/forum/discussion/7994/chat-like-conversations-for-harlowe

1 Answer

0 votes
by (159k points)

The you may want to consider using a solution similar to the one given for the Efficiently Creating 'Conversational Style' in Sugarcube question.

Something like the following prototype

{
Hi, how are you?<br>
|choice1>[
	(link: "I'm feeling great")[
		(replace: ?choice1)[I'm feeling great]
		(show: ?feeling-great)
	]
	<br>
	(link: "Not well!")[
		(replace: ?choice1)[Not well!]
		(show: ?not-well)
	]
]
|feeling-great)[
	<br>
	That's good to hear. Are you planing on going to the party?
	<br>
	(link: "Yes")[(show: ?party-yes)]
	<br>
	(link: "No")[(show: ?party-no)]
]
|not-well)[
	<br>
	I'm sorry to hear that, have you visited a doctor?
	<br>
	(link: "Yes")[(show: ?doctor-yes)]
	<br>
	(link: "No")[(show: ?doctor-no)]
]
|party-yes)[
<br>I'm looking forward to seeing you there.
]
|party-no)[
<br>That's sad, well maybe you'll change your mind.
]
|doctor-yes)[
<br>And what did they say?
]
|doctor-no)[
<br>You  might want to reconsider that.
]
}

 ... the above contain examples of how to show a hidden section of a passage based on the choice made by the Reaper/Player, it also shows how to replace a set of link options with the text of the one that was selected.

...