Converting strings to numbers in Twine Harlowe from URL

Hi everyone,

I am writing a collection of essays on Twine that have variables in the external URL so I have to convert certain elements from strings to numbers. I thought it would be possible to do this from the opening passage, but it seems I need to do it on every single passage in which I mention the variable. I have an inventory that returns to the last passage which, when I have converted as it is coming back to the same section calls up this error: The (num:) macro’s 1st value is the number 2, but should be a string, when the varaible is number 2. Anyone have any idea why this is happening? Should I resist using the return button? Why is (set: $adrenaline to (num:)) not working across the whole piece from the opening passage?

Many thanks in advance!

For further context, if I put the number conversion in the opening passage, it it is saying it must be given a string; automatically any variables in a url in coming into Harlowe are strings so I’m a little confused…

Hi everyone,

Hope you’re having a lovely week so far! Re-posting this question as haven’t had any luck if anyone has any suggestions - ive spent many hours trying to figure out a possible solution to no avail and feel there should be a simple means to do this in Twine Harlowe (the latest version).

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.

There are two issues with the values you are assigning to href attribute of your HTML <a> elements:

1: You are using double quotes as both

  • the delimiter of the String value you are assigning to href attribute.
  • the delimiter of the String value you are assigning to the i parameter of the URL

2: All values assigned to parameters of an URL are automatically treated as String values, which means you don’t need to quote the jo1 value being assigned to the i parameter of your URL.
eg. the following…

theseentangledmappings?a=3&i="jo1"

…should be just…

theseentangledmappings?a=3&i=jo1

So taking the above into account, the your <a> element declarations should look like…

<a href="theseentangledmappings?i=jo1" >These Entangled Mappings</a>

<a href="theseentangledmappings?a=3&i=jo1">These Entangled Mappings</a>

Regarding your earlier question about the (num:) macro, it only accepts String representations of valid numbers as its single argument.

(set: $age to (num: "37"))

So if you have a String value that only consists of digit related character…

(set: _postcode to "3563")

…then you can covert that String representation of a number into an actual number like so…

(set: $count to (num: _postcode))
1 Like