How can I link to a randomized set of URLs?

0 votes
asked Dec 6 by laurenmary (120 points)
I am just beginning a new project and want to link to a random URL. For example, If passage 1 said: I love [[cats]], then I would want the user to be able to click on cats and have it bring them (outside of the project) to one of the top 10 hits on google news for "cats." Again, I haven't started yet so I haven't picked a story format -- I will use whatever I can to make this work. I am partial to sugarcube, however. Any and all help would be greatly appreciated!!

2 Answers

0 votes
answered Dec 6 by Olzme (420 points)
edited Dec 6 by Olzme

The way I would do it in Sugarcube is set each url as a variable.
so ex

<<set $firstURL to 1>>

then use random to make the variable be randomly chosen between 1-10


then make another variable to be set as the one that grabs the URL chosen, and place that inside your passage link

EDIT: Ahh nevermind: I read that wrong, I thought the URLs were predetermined.   I guess you would need to be pulling APIs like Chapel mentioned...

0 votes
answered Dec 6 by Chapel (33,870 points)

If you want this to actually be automated in some way, meaning you want a dynamic set of links straight from Google to use in your story, you'll need to use their API, which is only sort of free. Then you'd grab the urls from the data and create some links. 

How easy this is for you to implement will depend on your programming knowledge. My knowledge of how to do something like this basically begins and ends with knowing that it can be done, so I can't offer you much more help than that, unfortunately. 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.