0 votes
by (160 points)
retagged by

Hello,

I require some advice on how to rationalise a section of my Harlow coding. I'm sure it can be done better.

Reading a lot of Le Carré novels, I wanted to put together a retro spy story. In it I have an event, where the player gets followed. I want the player to spot a few clues about the person following them, and piece the information together themselves later. I've one passage, which contains the various spy descriptions, and another that contains the event.

"spies"

{
<!-- SPIES -->
(set: $alfred to (dm:
	"active", false,
	"age", 25,
	"name", "Alfred Grey",
	"nation", "Britain",
	"attspot", "null",
	"attributes", (ds:
		"brown hair",
		"tall",
		"moustache"
		)
	))
(set: $chuck to (dm:
	"active", false,
	"age", 30,
	"name", "Chuck Dawson",
	"nation", "USA",
	"attspot", "null",
	"attributes", (ds:
		"blonde hair",
		"average",
		"beard"
		)
	))
(set: $robin to (dm:
	"active", false,
	"age", 42,
	"name", "Robin Lindmaa",
	"nation", "Estonia",
	"attspot", "null",
	"attributes", (ds:
		"red hair",
		"short",
		"clean shaven"
		)
	))
(set: $rene to (dm:
	"active", false,
	"age", 33,
	"name", "René Marchand",
	"nation", "France",
	"attspot", "null",
	"attributes", (ds:
		"brown hair",
		"average",
		"clean shaven"
		)
	))
(set: $ermolai to (dm:
	"active", false,
	"age", 27,
	"name", "Ermolai Kirov",
	"nation", "USSR",
	"attspot", "null",
	"attributes", (ds:
		"blonde hair",
		"tall",
		"moustache"
		)
	))
(set: $narek to (dm:
	"active", false,
	"age", 48,
	"name", "Narek Petrossian",
	"nation", "Armenia",
	"attspot", "null",
	"attributes", (ds:
		"red hair",
		"short",
		"beard"
		)
	))
<!-- SPY LIST -->
(set: $spy to (ds:
	$alfred,
	$chuck,
	$robin,
	$rene,
	$ermolai,
	$narek
	))
}

"event"

{
<!-- SPY SELECT -->
(set: $npc to (either:
	...$spy
	))
<!-- SPOTTED SPY ATTRIBUTE -->
(set: $npc's attspot to (either:
	...$npc's attributes
	))
<!-- ATTRIBUTE DESCRIPTION/SUSPECT -->
(if: $npc's attspot is "brown hair")[
	(set: $npcdesc to "They have brown hair.")
	(set: $suspect1 to $alfred, $suspect2 to $rene)
	]
(else-if: $npc's attspot is "tall")[
	(set: $npcdesc to "They are tall.")
	(set: $suspect1 to $alfred, $suspect2 to $ermolai)
	]
(else-if: $npc's attspot is "moustache.")[
	(set: $npcdesc to "They have a moustache.")
	(set: $suspect1 to $alfred, $suspect2 to $ermolai)
	]
(else-if: $npc's attspot is "blonde hair")[
	(set: $npcdesc to "They have blonde hair.")
	(set: $suspect1 to $chuck, $suspect2 to $ermolai)
	]
(else-if: $npc's attspot is "average")[
	(set: $npcdesc to "They are average in height.")
	(set: $suspect1 to $chuck, $suspect2 to $rene)
	]
(else-if: $npc's attspot is "beard")[
	(set: $npcdesc to "They have a beard.")
	(set: $suspect1 to $chuck, $suspect2 to $narek)
	]
(else-if: $npc's attspot is "red hair")[
	(set: $npcdesc to "They have red hair.")
	(set: $suspect1 to $robin, $suspect2 to $narek)
	]
(else-if: $npc's attspot is "short")[
	(set: $npcdesc to "They are short in height.")
	(set: $suspect1 to $robin, $suspect2 to $narek)
	]
(else-if: $npc's attspot is "clean shaven")[
	(set: $npcdesc to "They are clean shaven.")
	(set: $suspect1 to $robin, $suspect2 to $rene)
	]
}
In the window of an antiquated bookshop, you see a stranger following you.

(print: $npcdesc)

Remembering the dossier, you have some suspects in mind:
1. (print: $suspect1's name)
2. (print: $suspect2's name)

The event works well, but the 'Attribute description/suspect' part is unwieldy. I was thinking of using Lamdas, but I'm struggling getting my loaf around them. I've already managed to nest datasets containing attributes, inside each spy's datamaps; maybe this is the way forward.

I also hoping there was a way I could connect up the suspect identifier, to the attribute, so I wouldn't have to set them for each one, and they'd be called automatically.

Any help would be greatly appreciated.

1 Answer

+1 vote
by (1.1k points)
selected by
 
Best answer

The descriptions are easy: just put them in a datamap:

<!-- DESCRIPTION LIST -->
(set: $spyDescriptions to (dm:
	"brown hair", "They have brown hair.",
	"tall", "They are tall.",
	"moustache", "They have a moustache.",
	"blonde hair", "They have blonde hair.",
	"average", "They are average in height.",
	"beard", "They have a beard.",
	"red hair", "They have red hair.",
	"short", "They are short.",
	"clean shaven", "They are clean shaven."
))

Then you can:

(set: $npcdesc to $npc's attspot of $spyDescriptions)

You can use "find" to get a list of the spies who match the attribute which was spotted:

(set: $suspects to (find: _suspect where _suspect's attributes contains $npc's attspot, ...$spy))

Use a for loop to display the suspects.  Since you want to number them, I think you have to loop over a range, and then grab the npc from the spy list using the number:

(for: each _i, ...(range: 1,$suspects's length))[
	(print: _i): (print: $suspects's (_i)'s name)]

Hope that helps...

by (160 points)
Cheers mate!

That works like a charm. First time I've used an 'of', 'where' and 'find:'

I'm going to go away a try to use Lambda data more often.

I have a dream, one day I'll make a twine story that conclusivly uses every single possible command, function and everything in between. Next I'll have to work out how to slip use of sin and cos function into the spy story.
...