0 votes
by (210 points)

Hi everyone,

I am trying to randomize the selection of passage based on their relative weight. I think that I grasped the logic of how I could make it works with datamaps, but my programming abilities are...well, they are not. I am using Harlowe 3.0.2.

For now, I have this:

(set: $passage_weights to (dm: "passage1", 2, "passage2", 1))


(set: $passage_choices to (a: [?])


(set: $passage to (either: ...$passage_choices))

In this example, passage1 should have two chances to be selected, while passage2 should have one.

I think that all I am missing is the [?] part. What I aim for is to convert the datamap in something like this: ("passage1", "passage1", "passage2").

Then, with the either macro, all shoud work as I want. Is there anyway to do something like this?

1 Answer

0 votes
by (210 points)

All right, I think that I figured it out. Can you have a look a this? It seems to work out fine but perhaps there is an issue that I am not seeing.

<set chance for each passage-->

(set: $passage_weights to (dm: "passage1", 2, "passage2", 1))

<merging all chances-->
(set: $passage_choices to ( 
	(repeated: $passage_weights's "passage1", "passage1")
	+(repeated: $passage_weights's "passage2", "passage2")
	)
)

<choosing one passage-->
(set: $passage_chosen to (either: ...$passage_choices))

<showing passage-->
[[$passage_chosen]]

 

...