Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help using recursive loop with (datanames:) and (datavalues:) to browse a (datamap:) in Harlowe

Hello! I'm trying to use a recursive loop to make a way for the player to explore a datamap which will collect all the knowledge they've gained about the world. So, for example, I'd initialise the datamap with something like this:
(set: $knowledge to (datamap:
"people", (datamap:),
"world", (datamap:),
"history", (datamap:),
))

(set: "people" of $knowledge to it + (datamap:
"Traveller's Friend", "A woman wrapped in winding sheets who brought you to this place",
"Arbiter", "Those whose rigid governance maintains the order upon which your old life was built"

))

And then in the story, you could browse it using something like this:
People:
(print: (datanames: "people" of $knowledge).join("
")) 
(set: $peopleNumber to (datanames: ("people" of $knowledge))'s length)
(set: $i to 0)
(display: "PeopleKnowledgeLooper")

with the PeopleKnowledgeLooper page looking like this:
(if: $i < $peopleNumber)[
(clickappend: (string: (datanames:"people" of $knowledge)[$i]))[(print: " - " + (string:(datavalues: "people" of $knowledge)[$i]))]
(set:$i to it + 1)(display: "PeopleKnowledgeLooper")]

My desired endpoint would be a system where all the names of the characters you have met are displayed in a list as links, and when you click on them they are appended with whatever you know about them. At the moment, clicking on the names only appends them with " - ", but the string from the (datavalues:) macro comes out blank and empty, and I can't quite see why that should be happening. The code works fine when I drop a static value in instead of my iterator variable, and even when I use $i to iterate through the loop the code inside the (clickappend:) macro works fine (the names become links). The problem is with the code inside the hook, but as that code is practically identical then I can't see where I'm going wrong. Any advice appreciated!

Thanks,

Ed
Sign In or Register to comment.