I’m trying to figure out if it’s possible to set variables in a twine story as a string in the opening URL. So, if someone opens the story from an email, they could have ?name=thisperson in it, to give some customisation from the get-go.
I’m new to twine, but couldn’t see anything on here suggesting that it was/ wasn’t possible. Any pointers would be greatly appreciated!
Yes, you can do that, though the exact method depends on what Story Format you’re using (e.g. Harlowe, SugarCube, etc.). If you set the optional tag on your post to your Story Format, that makes it easier for us to provide you the correct support.
If you’re using SugarCube, you could put this in your JavaScript section:
setup.name = (new URLSearchParams(document.location.search)).get("name");
And that would set $name to the .name property on the setup object which we set earlier in the JavaScript section, or if a name isn’t in the URL, it sets $name to an empty string.
If you need to support Internet Explorer (which is a good idea, because a surprisingly large number of people are still using it) you can use this URLSearchParams Polyfill to provide the same functionality within the later versions of that browser.