Less complex way to use else/if statements to add elements onto an html link

Twine Version:
[Harlowe]

Hi there, hope everyone is keeping well and having a nice weekend!

I have several twine stories which link together at various moments with variables added into the html based on elements picked up. This all works successfully at the receiving end but I am trying to find a more trustworthy and less complicated and lengthy (!) means to change the ends of the html link based on the inventory.

Currently this involves writing code like this:

(if: $inventoryofthinkers contains "Jenny Oddell)")[<a href="theseentangledmappings?i="jo1"" >These Entangled Mappings</a>]] 
(if: $inventoryofthinkers contains "Jenny Oddell" and $adrenaline is "3")[<a href="theseentangledmappings?a=3&i="jo1"" >These Entangled Mappings</a>]]

There are a lot of sources in my inventory so I was basically wondering if there is a means to say - add this element onto the html - rather than come up with (possible tens of different options of combinations).

Hope this makes some sense and realise this may not be possible! Thanks so much in advance.

Essentially, you still have to “check” each variable you want to send, but you can do it a bit more streamlined. I don’t know the context or what you want to pull across through the URL, but here are some ideas:

(set: _varList to "")
(if: $inventoryofthinkers contains "Jenny Oddell")[
  (set: _varList to it + "&i=jo1")
]
(set: _varList to it + "&a=" + $adrenaline)

(set: _url to "theseentangledmappings?x=x" + _varList)
<a href="_url" >These Entangled Mappings</a>

I just add & in front of each variable that’s added to the list. This creates a possible string of &i=jo1&a=3 and that is why I added ?x=x before appending that string of variables. You’ll notice that I used temporary variables with the _ character as well. I also use it to condense the code a bit.

I hope these ideas help you refactor your code into something more manageable.

Edit: Also, you don’t have to put quotes in the values sent in the URL. URL variables are all understood as strings regardless if they are a number or not… which means you have to use the (num:) macro to convert a URL number to a number data type to use again in Harlowe.